Fifteenth Hunan University Programming Contest (reproduce the race)

I Algorithm Choosing Mushrooms

Time limit: C / C ++ 1 second, 2 seconds languages other
space restrictions: C / C ++ 32768K, other languages 65536k
64bit the IO the Format: LLD%

Title Description

Baby bear and his good friends are very fond of mushrooms. On this day, they go to 402 mushroom field together. Kuangyeye, the owner of the mushroom field, is very happy to see the children. He is going to give the children some mushrooms, so he takes them to a warehouse.

In the warehouse, there are N baskets in a row, numbered from 1 to N, with some mushrooms in each basket. Baby bear and his friends can take several baskets of mushrooms, but Kuangyeye has several requirements:

·Kuangyeye likes to be neat and tidy. He asks the children to take away only the consecutively numbered baskets when they take the mushrooms. This means that if the children choose the 4th, 5th and 6th baskets of mushrooms, they can't choose the 9th basket unless they also choose the 7th and 8th baskets.

·Kuangyeye likes all of them, so he asks each child to get the same number of mushrooms. This means that the total number of mushrooms the children take away must be P = k * M, where k is an integer and M is the total number of children.

·Kuangyeye made a record of the number of mushrooms in each basket. He asks the children not to put some mushrooms in other baskets or throw them away. This means that when the children take a basket of mushrooms, they must take away all the mushrooms in the basket.

Now given the number of mushrooms in a row of N baskets, please answer:

1. The maximum number of mushrooms that baby bear and his friends can take away.

2. The maximum number of baskets that baby bear and his friends can take away.

Please note that the answers to questions 1 and 2 May not come from the same situation!!!

Enter a description:

The input contains a single sample.

The first line of input has two integers N and M (1 <= N,M <= 200000) separated by space, representing the number of baskets and the number of children.

The second line of input has N integer A1,A2,……,AN (1 <= A1,A2,……,AN <= 1e9)separated by space, representing the number of mushrooms in the basket numbered from 1 to N.

Output Description:

Output two Numbers separated by space. The maximum number of mushrooms they could get and the maximum number of baskets they could take. If they can’t meet Kuangyeye's demands, please output “0 0”.
Example 1

Entry

copy
8 7
2 1 15 5 8 9 1 7000

Export

copy
7000 3

Explanation

Choose basket 8 to get the most mushrooms, but choose basket 2, 3, 4 (or 3, 4, 5) to get the most baskets.
Example 2

Entry

copy
7 13
7 1000 1000 1000 1000 1000 6

Export

copy
0 0

Explanation

It's impossible to meet Kuangyeye's demands.
 
This problem did not do it orz
 1 //江寒月熙丶 提交的代码https://ac.nowcoder.com/acm/contest/view-submission?submissionId=40729426
 2 
 3 #include <bits/stdc++.h>
 4 #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 5 #define IT set<node>::iterator
 6 #define mem(a) memset(a,0,sizeof(a))
 7 using namespace std;
 8 typedef long long LL;
 9 typedef long long ll;
10 const int maxn=1e6+5;
11 ll a[maxn];
12 ll start[maxn];
13 ll sumzz[maxn];
14 unordered_map<int,int>mp;
15 int main()
16 {
17     #ifdef ONLINE_JUDGE
18     FAST_IO;
19     #endif // ONLINE_JUDGE
20    int n,k;
21    cin>>n>>k;
22    for(int i=1;i<=n;i++)
23         cin>>a[i],sumzz[i]=sumzz[i-1]+a[i];
24    ll sum=0;
25    ll ans=0;
26    ll maxz=0;
27    for(int i=1;i<=n;i++)
28    {
29        sum=(sum+a[i])%k;
30        if(sum!=0&&start[sum]==0)
31             start[sum]=i;
32        else {
33         ans=max(ans,i-start[sum]);
34         maxz=max(maxz,sumzz[i]-sumzz[start[sum]]);
35        }
36    }
37    cout<<maxz<<' '<<ans<<endl;
38 }
Jiang Xi Dian Code Hanyue submitted

 

Learn about Gangster code orz first time that unordered_map, so I want to add something new knowledge get in!
 
 
C One Piece
Time limit: C / C ++ 1 second, 2 seconds languages other
space restrictions: C / C ++ 32768K, other languages 65536k
64bit the IO the Format: LLD%

Title Description

Luffy once saw a particularly delicious food, but he didn't have the money, so he asked Nami for money. But we all know that Nami can't easily give money to Luffy. Therefore, Nami decided to take a test of Luffy. If Luffy was right, Nami would give him money, otherwise Luffy would only be hungry. The problem is as follows: Give you an 32-bit integer n and find the number of 1 in the binary representation of the integer.
You are the most trusted friend of Luffy, and he is now asking for help.

Enter a description:

There are multiple test cases. The first line of the input contains an integer T(T<=10), indicating the number of test cases. For each test case:

The first line contains an 32-bit integer n(-1e9 <= n <= 1e9)

Output Description:

For each test case output one line containing one integer, indicating the number of  1 in the binary representation of the integer.
Example 1

Entry

copy
3
1
2
3

Export

copy
1
1
2

Explanation

The binary of 1 is 01, so the number of 1 is 1, and the binary of  2 is 10, so the number of 1 is 1,The binary of 3 is 11, so the number of 1 is 2.
Example 2

Entry

copy
1
-1

Export

copy
32

Explanation

The binary of -1 is 11111111111111111111111111111111, so the number of 1 is 32.
 
 1  
 2 void Binarycout(int n) 
 3 { 
 4     int cnt;
 5     for (int i=31;i>=0;i--) 
 6     { 
 7      if(((n>>i)&1)==1)
 8         cnt++; 
 9     } 
10     cout<<cnt<<endl; 
11 }
12  
13 int main()
14 {
15     long long t,n;
16     scanf("%lld",&t);
17     while(t--)
18     {
19         scanf("%lld",&n);Binarycout(n);
20     }
21      
22     return 0;
23 }
My question 5ms C
 Night faded codes submitted 2ms
 1 int main()
 2 {
 3      
 4     int t;scanf("%d",&t);
 5     while(t--)
 6     {
 7         int value = 0;
 8         int count = 0;
 9         scanf("%d",&value);
10         while(value != 0)
11         {  
12             count++;
13             value = (value & (value-1));
14         }
15         printf("%d\n",count);
16     }
17     return 0;
18 }
Seniors get together code

 

 

F  Cards with Numbers

Time limit: C / C ++ 1 second, 2 seconds languages other
space restrictions: C / C ++ 262144K, other languages 524288K
64bit the IO the Format: LLD%

Title Description

AFei has many cards. Each card has a number written on it. Now he wants to takes some out of his card and puts them in a box. And he wants to know whether the card with the number x was in the box. So he has the following two operations:
  • 0 x (It means to put a card with the number x in the box.)
  • 1 x   (It means to query if there is a card with the number x in the box.)

Enter a description:

The first line of the input is an integer n (1 <= n <= 10
6
), the number of operations. Next n lines  represent n operations, and two integers k ( k∈{0,1}) and x (0<=x<=10
9
)  are separated by spaces on each line, as described above.

Output Description:

For each query, output one line "yes" if there is a card with the number x in the box, otherwise output one line "no".
Example 1

Entry

copy
5
0 1
1 2
0 2
1 3
1 2

Export

copy
no
no
yes
 Solution: This problem twists and turns. First start using a bucket placed. Regardless of the result is int or bool arrays, which are mle (the first segment error because fewer hit a 0, but be aware of before the addition of 0, but not too concerned about mle), then changed to map tle. . Finally, the vector + bool AC.
 1 int main()
 2 {
 3     //memset(a,false,sizeof(a));
 4     int x;
 5     int t;
 6     scanf("%d",&t);
 7     vector<bool > v(1e9);
 8     int q;
 9     while(t--)
10     {
11         scanf("%d%d",&q,&x);
12         if(q==0)
13             v[x]=true;
14         if(q==1)
15         {
16             if(v[x]==true)
17                 printf("yes\n");
18             else
19                 printf("no\n");
20         }
21     }
22 }
F

Read other chiefs of the code, in fact, may modulo processing, but a bit of trouble ~ ~ trained, trained, trained,

 1 /*Jadlokin_Scarlet 提交的代码https://ac.nowcoder.com/acm/contest/view-submission?submissionId=40728436*/
 2 
 3 
 4 int n,f,x;
 5 unordered_set<int> s;
 6 int main() {
 7     scanf("%d",&n);
 8     while(n--){
 9         scanf("%d %d",&f,&x);
10         if(f == 0){
11             s.insert(x);
12         }else {
13             printf(s.count(x) == 1?"yes\n":"no\n");
14         }
15     }
16     return 0;
17 }
Code Jadlokin_Scarlet submitted

U nordered the SET . . The original unordered STL applications such extensive QWQ ||| This is also the code brief submission of mainstream practice

 1 const int maxn=1000000100;
 2 int n,c,x;
 3 bitset<maxn> vis;
 4 int main()
 5 {
 6     cin>>n;
 7     while(n--)
 8     {
 9         scanf("%d%d",&c,&x);
10         c?printf(vis[x]?"yes\n":"no\n"):vis[x]=1;
11     }
12     return 0;
13 }
Code hnust_liuzelin submitted

This feels more powerful way orz   bitset

Links: https://ac.nowcoder.com/acm/contest/908/G
Source: Cattle-off network

G Longest Palindrome Substring

Time limit: C / C ++ 1 second, 2 seconds languages other
space restrictions: C / C ++ 32768K, other languages 65536k
64bit the IO the Format: LLD%

Title Description

    A palindrome is a symmetrical string, that

is, a string read identically from left to right as well as from right to left. For example, ”a”、”aba”、“abba” are palindrome and “abc”、”aabb” are not.

    Let’s define a new function f(s).

    For some string s, f(s) is the length of the longest palindrome substring.

    Now you should decide for the given string s, whether f(s) is great than 1.
    The string s only contains lowercase letters.
 

Enter a description:

The first line of the input contains one integer n ------ the length of the string (1<=n<=10^5)

The second line of the input is the string.

Output Description:

If f(s) great than 1, print “YES” without quote

Else print “NO” without quote
Example 1

Entry

copy
4
abcd

Export

copy
NO
Example 2

Entry

copy
4
abcb

Export

copy
YES
..
 1 #include <stdio.h>
 2 int main()
 3 {
 4     int n,i,flag=0;
 5     char s[100000];
 6     scanf("%d",&n);
 7     getchar();
 8     gets(s);
 9     for(i=0;i<n;i++){
10         if(s[i]==s[i+1]||s[i]==s[i+2])
11         {
12             flag=1;
13             break;
14         }
15     }
16     if(flag==1){
17         printf("YES\n");
18     }
19     else{
20         printf("NO\n");
21     }
22  }
G

 

..
 
 

Guess you like

Origin www.cnblogs.com/greenaway07/p/10960667.html