Codeforces Round #636 (Div. 3)
题目链接:http://codeforces.com/contest/1343
A
思路:for循环搞一下,从2开始,i*=2,累加和,当n%sum==0就行了,就说明整除了
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 }
B
思路:看例题的结果解析没啥用,自己找例子,2468,和1379,这俩和相等,你就发现偶数的首尾之和等于奇数的首尾之和,由外两边向内两边每取两个数和都为偶数首尾之和,那么偶数部分正常等差输出即可,奇数分布就把每组19,37,插入动态数组,sort一下输出就好了
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 }
C
思路:就是在数组里找长度尽可能大的序列+-+-+-+-.../-+-+-+...,使其和最大,那么只要找每个相同符号的一段里面的最大值即可,将其相加,注意下什么时候加值即可
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 }