A.The Fool
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 inline int read() 5 { 6 int x=0,f=1;char ch=getchar(); 7 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 8 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 9 return x*f; 10 } 11 12 /********************************************************************/ 13 14 int main(){ 15 int t; t = read(); 16 int cnt = 0; 17 while(t--){ 18 cnt++; 19 int n; n = read(); 20 int last = 0; 21 int ans = 0; 22 for(int i = 1;i <= n;i = last){ 23 int j = n/(n/i); 24 ans += (j-i+1)*(n/i); 25 last = j+1; 26 } 27 if(n&1) printf("Case %d: odd ", cnt); 28 else printf("Case %d: even ", cnt); 29 } 30 return 0; 31 }
B.The World
模拟
C.Justice
1 //似乎卡过去了,可能需要更优化 2 3 4 #include <bits/stdc++.h> 5 using namespace std; 6 7 inline int read() 8 { 9 int x=0,f=1;char ch=getchar(); 10 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 11 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 12 return x*f; 13 } 14 15 /********************************************************************/ 16 17 const int maxn = 1e5+5; 18 19 struct node{ 20 int id; 21 int val; 22 vector<int>son; 23 }now; 24 25 vector<node>a; 26 int num[maxn]; 27 28 bool cmp(node x, node y){ 29 return x.val < y.val; 30 } 31 32 int main(){ 33 int t = read(); 34 int cnt = 0; 35 while(t--){ 36 37 memset(num, 0, sizeof(num)); 38 a.clear(); 39 cnt++; 40 int n = read(); 41 for(int i = 1;i <= n;i++){ 42 now.val = read(); 43 now.id = i; 44 now.son.clear(); 45 a.push_back(now); 46 } 47 48 printf("Case %d: ", cnt); 49 if(n == 1){ printf("NO "); continue;} 50 bool ok = true; 51 sort(a.begin(), a.end(), cmp); 52 while(ok){ 53 //sort(a.begin(), a.end(), cmp); 54 if(a.size() == 2) break; 55 if(a[0].val == 1 && a[1].val == 1) break; 56 ok = false; 57 vector<node>::iterator it = a.end()-1; 58 for(;it != a.begin();it--){ 59 if((*it).val == 1) continue; 60 if((*it).val == (*(it-1)).val){ 61 ok = true; 62 vector<node>::iterator it1 = it-1; 63 int itlen = (*it).son.size(); 64 for(int j = 0;j < itlen;j++){ 65 (*it1).son.push_back((*it).son[j]); 66 } 67 (*it1).son.push_back((*it).id); 68 (*it1).val--; 69 /* 70 sort((*it1).son.begin(), (*it1).son.end()); 71 (*it1).son.erase(unique((*it1).son.begin(), (*it1).son.end()), (*it1).son.end()); 72 */ 73 a.erase(it); 74 it++; 75 } 76 if(a.size() == 2) break; 77 } 78 sort(a.begin(), a.end(), cmp); 79 } 80 /* 81 for(int i = 0; i<a.size();i++){ 82 cout << i+1 << " : " << a[i].val << endl; 83 } 84 */ 85 if(a[0].val == 1 && a[1].val == 1){ 86 printf("YES "); 87 int valen = a[0].son.size(); 88 num[a[0].id] = 1; 89 for(int i = 0;i < valen;i++){ 90 num[a[0].son[i]] = 1; 91 } 92 for(int i = 1;i <= n;i++) 93 printf("%d", num[i]); 94 printf(" "); 95 } 96 else printf("NO "); 97 98 } 99 return 0; 100 }