POJ2965 The Pilots Brother's Refrigerator
看完标程觉得自己是傻逼
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn=50000+10; 7 int res[10][10]; 8 9 int main() { 10 char c; 11 for (int i=1; i<=4; ++i) { 12 for (int j=1; j<=4; ++j) { 13 cin>>c; 14 if (c=='+') { 15 for (int k=1; k<=4; ++k) { 16 res[i][k]^=1; 17 res[k][j]^=1; 18 } 19 res[i][j]^=1; //(i,j)被按了两次 20 } 21 } 22 } 23 int cnt=0; 24 for (int i=1; i<=4; ++i) 25 for (int j=1; j<=4; ++j) 26 if(res[i][j]) ++cnt; 27 printf("%d\n", cnt); 28 for (int i=1; i<=4; ++i) 29 for (int j=1; j<=4; ++j) 30 if(res[i][j]) 31 printf("%d %d\n", i, j); 32 return 0; 33 }
CH0802 占卜DIY
直接模拟
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn=50000+10; 7 deque<int> q[15]; 8 9 int life=4, now, cnt[15]; 10 void process() { 11 now=q[13].front(); 12 q[13].pop_front(); 13 if (now==13) { //unfortunately 14 life--; 15 if (life==0) return; 16 process(); 17 if (life==0) return; 18 } 19 else { 20 cnt[now]++; 21 q[now].push_front(now); 22 } 23 } 24 25 int main() { 26 for (int i=1; i<=13; ++i) { 27 for (int j=1; j<=4; ++j) { 28 char s[3], c; 29 scanf("%s", s); 30 c=s[0]; 31 if (c=='0') q[i].push_back(10); 32 else if (c=='A') q[i].push_back(1); 33 else if (c=='J') q[i].push_back(11); 34 else if (c=='Q') q[i].push_back(12); 35 else if (c=='K') q[i].push_back(13); 36 else q[i].push_back(c-'0'); 37 } 38 } 39 process(); 40 while (life) { 41 int tmp=now; 42 now=q[now].back(); 43 q[tmp].pop_back(); 44 if (now==13) { //unfortunately 45 life--; 46 if (life==0) break; 47 process(); 48 if (life==0) break; 49 } 50 cnt[now]++; 51 q[now].push_front(now); 52 } 53 int ans=0; 54 for (int i=1; i<=13; ++i) 55 if (cnt[i]>=4) { 56 ++ans; 57 //printf("%d ", i); 58 } 59 /*for (int i=1; i<=13; ++i) 60 printf("%d ", cnt[i]);*/ 61 //printf("\n"); 62 printf("%d\n", ans); 63 return 0; 64 }
CH0805 防线/BZOJ1271 秦腾与教学评估
二分答案,然后统计,查看是否是奇数
1 //二分 2 #include3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn=200000+10; 8 int n, s[maxn], e[maxn], d[maxn]; 9 int m=0; 10 long long sum=0; 11 12 bool check(int pos) { 13 sum=0; 14 for (int i=1; i<=n; ++i) { 15 if (s[i]<=pos) { 16 if (e[i]<=pos) sum+=(long long)(e[i]-s[i])/d[i]+1; 17 else sum+=(long long)(pos-s[i])/d[i]+1; 18 } 19 } 20 //printf("%d %d\n", pos, sum); 21 return (sum%2); 22 } 23 24 void print(int pos) { 25 long long ans=0; 26 for (int i=1; i<=n; ++i) { 27 if (s[i]<=pos&&e[i]>=pos) { 28 int t=(pos-s[i])%d[i]; 29 if (t==0) ans++; 30 } 31 } 32 printf("%d\n", ans); 33 } 34 35 int main() { 36 int T; 37 scanf("%d", &T); 38 while (T--) { 39 scanf("%d", &n); 40 for (int i=1; i<=n; ++i) { 41 scanf("%d%d%d", &s[i], &e[i], &d[i]); 42 m=max(m, e[i]); 43 } 44 int l=1, r=m+1, mid; 45 while (l<r) { 46 mid=(l+r)>>1; 47 if (check(mid)) r=mid; 48 else l=mid+1; 49 } 50 if (r==m+1) printf("There's no weakness.\n"); 51 else { 52 printf("%d ", r); 53 print(r); 54 } 55 } 56 return 0; 57 } 58 /* 59 3 60 2 61 1 10 1 62 2 10 1 63 2 64 1 10 1 65 1 10 1 66 4 67 1 10 1 68 4 4 1 69 1 5 1 70 6 10 1 71 */
CH0807 糖果传递
和七夕祭类似
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 const int maxn=1000000+10; 9 long long n, a[maxn], s[maxn]; 10 11 int main() { 12 scanf("%lld", &n); 13 long long sum=0; 14 for (int i=1; i<=n; ++i) { 15 scanf("%lld", &a[i]); 16 sum+=a[i]; 17 } 18 for (int i=1; i<=n; ++i) 19 a[i]-=sum/n; 20 s[1]=a[1]; 21 for (int i=2; i<=n; ++i) 22 s[i]=s[i-1]+a[i]; 23 sort(s+1, s+n+1); 24 long long median=s[n/2+1]; 25 long long ans=0; 26 for (int i=1; i<=n; ++i) 27 ans+=abs(s[i]-median); 28 printf("%lld\n", ans); 29 return 0; 30 }