这次打cf第一次长分,比赛时做了A、B、C三道题,赛完了再做了D题。比赛开始两题很快就过了,一个7分钟一个30分钟,不过还是感觉英语着急,看题用了很长的时间。第三题就更蛋疼了,看了半个小时没看明白,代码也连交了两次WA,最后发现是修改代码的时候一个地方忘记删掉了,删了就直接A,不过也没时间了,第四题就没怎么看了。到后面测大数据的时候就坑了,第三题竟然Wrong answer on 34,看了下数据,确实贪心的思路有问题,不过在加个枚举就应该对了,改了一下AC。感觉有点遗憾,不过cf真心好玩,以后一定要坚持打,希望能分数越来越高
#include<iostream> #include<string> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define N 105 int main () { string s; while(cin >> s) { int num[N]; int len = s.size(), t = 0; for(int i = 0; i < len ; i++) { if(s[i] >= '1' && s[i] <= '3') num[t++] = s[i]-'0'; } sort(num, num+t); for(int i = 0; i < t-1; i++) printf("%d+", num[i]); printf("%d\n",num[t-1]); } return 0; }
#include<stdio.h> #define N 100005 int a[N]; int main () { int n, m; int i, j; while(scanf("%d %d", &n, &m) != EOF) { __int64 ans = 0; for(i = 1; i <= m; i++) scanf("%d", &a[i]); ans = a[1] - 1; for(i = 2; i <= m; i++) { if(a[i] == a[i-1]) continue; if(a[i] > a[i-1]) {ans += a[i]-a[i-1]; continue;} if(a[i] < a[i-1]) {ans += (n-a[i-1]+1) + a[i]-1; continue;} } printf("%I64d\n", ans); } return 0; }
#include<stdio.h> int ans[1005]; int main () { int s[15]; char num[15]; int i, j; while(scanf("%s", num) != EOF) { int t = 0; for( i = 0; i < 10; i++) { if(num[i] == '1') s[t++] = i+1; } int n, cnt; scanf("%d", &n); for(int k = 0; k < t; k++) { cnt=1; int l = 0, r = 0, flag = 0; int lnum = -1, rnum = -1; flag = 1; l = s[k]; lnum = s[k]; ans[cnt++] = s[k]; for(j = 2; j <= n; j++) { if(!flag) //flag = 0, 放左边 { flag = 1; for( i = 0; i < t; i++) { if(s[i] == rnum) continue; if(l+s[i] > r) { l += s[i]; lnum = s[i]; ans[cnt++] = s[i]; break; } } if(i == t) break; } else { flag = 0; for( i = 0; i < t; i++) { if(s[i] == lnum) continue; if(r+s[i] > l) { r += s[i]; rnum = s[i]; ans[cnt++] = s[i]; break; } } if(i == t) break; } } if(j-1 == n) break; } if(j-1 == n) { printf("YES\n"); for(int i = 1; i < cnt-1; i++) printf("%d ", ans[i]); printf("%d\n", ans[cnt-1]); } else printf("NO\n"); } return 0; }
#include<stdio.h> #define N (1<<18)+10 #define lson l,m,s<<1 #define rson m+1,r,s<<1|1 int tree[N<<2]; int n, m, temp_n; void PushUp(int s, int count) { if((temp_n-count) % 2 != 0)//从底往上找是第几层,基数层进行or运算,偶数层进行xor运算 tree[s] = tree[s<<1] | tree[s<<1|1]; else tree[s] = tree[s<<1] ^ tree[s<<1|1]; } void updata(int p, int d, int l, int r, int s, int count) { if(l == r) { tree[s] = d; return ; } int m = (l+r) >> 1; if(m >= p) updata(p,d,lson,count+1); else updata(p,d,rson,count+1); PushUp(s, count); } int main () { int i, j; scanf("%d %d", &n, &m); temp_n = n; n = 1 << n; for(i = 1; i <= n; i++) { int num; scanf("%d", &num); updata(i, num, 1, n, 1, 0); } for(i = 1; i <= m; i++) { int p, d; scanf("%d %d", &p, &d); updata(p, d, 1, n, 1, 0); printf("%d\n", tree[1]); } return 0; }