Codeforces Round #636 (Div. 3)

Title link: http://codeforces.com/contest/1343

A

Idea: For loop, start from 2, i * = 2, cumulative sum, when n% sum == 0, it means that the whole

 1 //-------------------------------------------------
 2 //Created by HanJinyu
 3 //Created Time :二  4/21 22:34:17 2020
 4 //File Name :636A.cpp
 5 //-------------------------------------------------
 6 
 7 #include <stdio.h>
 8 #include <string.h>
 9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <map>
15 #include <list>
16 #include <map>
17 #include <string>
18 #include <math.h>
19 #include <stdlib.h>
20 #include <time.h>
21 using namespace std;
22 typedef double db;
23 typedef long long ll;
24 const int maxn = 200005;
25 
26 int main()
27 {
28     //freopen("in.txt","r",stdin);
29     //freopen("out.txt","w",stdout);
30     int T;
31     scanf("%d",&T);
32     while(T--){
33         ll n;
34         scanf("%lld",&n);
35         ll sum=0;
36         for(ll i=1;;i*=2)
37         {
38             sum+=i;
39             if(n%sum==0&&i!=1)
40             {
41                 printf("%lld\n",n/sum);
42                 break;
43             }
44         }
45     }
46 
47     return 0;
48 }
View Code

B

Idea: It is useless to see the result analysis of the example problem. Find examples by yourself, 2468, and 1379, these two are equal, you will find that the sum of the even numbers is equal to the sum of the odd numbers. The number sum is the sum of the first and last even, then the even part of the output can be normal, and the odd distribution can insert each group of 19 and 37 into the dynamic array and sort the output.

 1 //-------------------------------------------------
 2 //Created by HanJinyu
 3 //Created Time :二  4/21 23:17:11 2020
 4 //File Name :636B.cpp
 5 //-------------------------------------------------
 6 
 7 #include <stdio.h>
 8 #include <string.h>
 9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <map>
15 #include <list>
16 #include <map>
17 #include <string>
18 #include <math.h>
19 #include <stdlib.h>
20 #include <time.h>
21 using namespace std;
22 typedef double db;
23 typedef long long ll;
24 const int maxn = 200005;
25 
26 int main()
27 {
28     //freopen("in.txt","r",stdin);
29     //freopen("out.txt","w",stdout);
30     int t;
31     scanf("%d",&t);
32     while(t--)
33     {
34         int n;
35         scanf("%d",&n);
36         if(n%4==0)
37         {
38             printf("YES\n");
39             vector<ll>vv;
40             for(ll i=2;i<=2*(n/2);i+=2)
41                 printf("%lld ",i);
42             for(int i=0;i<n/4;i++)
43             {
44                 ll mm=i*2+1;
45                 ll nn=2+n;
46                 vv.push_back(mm);
47                 vv.push_back(nn-mm);
48             }
49             sort(vv.begin(),vv.end());
50             for(int i=0;i<vv.size();i++)
51                 printf("%lld ",vv[i]);
52             printf("\n");
53         } else
54             printf("NO\n");
55     }
56 
57     return 0;
58 }
View Code

C

Idea: Find the sequence as long as possible in the array +-+-+-+ -... /-+-+-+ ..., to make it the largest, then only find a section of each same symbol The maximum value is just to add them together, pay attention to when to add value

 1 //-------------------------------------------------
 2 //Created by HanJinyu
 3 //Created Time :二  4/21 23:17:11 2020
 4 //File Name :636B.cpp
 5 //-------------------------------------------------
 6 
 7 #include <stdio.h>
 8 #include <string.h>
 9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <map>
15 #include <list>
16 #include <map>
17 #include <string>
18 #include <math.h>
19 #include <stdlib.h>
20 #include <time.h>
21 using namespace std;
22 typedef double db;
23 typedef long long ll;
24 const int maxn = 200005;
25 const ll xiao=-1e9;
26 int main()
27 {
28     //freopen("in.txt","r",stdin);
29     //freopen("out.txt","w",stdout);
30     int t;
31     scanf("%d",&t);
32     while(t--) {
33         int n;
34         scanf("%d", &n);
35         ll a[maxn];
36         ll zheng=0,fu=xiao,sum=0;
37         for(int i=0;i<n;i++)
38         {
39             scanf("%lld",&a[i]);
40         }
41         a[n]=0;
42         for(int i=0;i<=n-1;i++)
43         {
44             if(a[i]>0&&a[i]>zheng)
45             {
46                 zheng=a[i];
47             }
48             if(a[i]<0&&a[i]>fu)
49             {
50                 fu=a[i];
51             }
52             if(a[i]<0&&a[i+1]>=0)
53             {
54                 sum+=fu;fu=xiao;
55             }
56             else if(a[i]>0&&a[i+1]<=0)
57             {
58                 sum+=zheng;zheng=0;
59             }
60         }
61         if(n==1)
62             printf("%lld\n",a[0]);
63         else {
64             printf("%lld\n", sum);
65         }
66     }
67 
68     return 0;
69 }
View Code

 

Guess you like

Origin www.cnblogs.com/Vampire6/p/12749184.html
Recommended