AtCoder Beginner Contest 072
这应该是我第二次打AtCoder, 题目其实并不难,就是自己经验不足想复杂了,再加上自己很笨,愣是做了97分钟才全做出来(最后三分钟,有点小激动。。),看着前面大牛半个小时都搞完了,真心膜拜一下,代码其实没什么可看的,题目也没什么可说的,就是为了贴出来总结经验,下次再战!
链接:http://abc072.contest.atcoder.jp/
A:直接做就可以了
#include<bits/stdc++.h> using namespace std; const int INF = (1 << 30); const int N = 100000 + 5; const double eps = 1e-8; const int M = 100 + 5; const int MOD = 1e9; char str[N]; int main(){ int x, t; scanf("%d %d", &x, &t); printf("%d\n", max(x - t, 0)); }
B:也是直接做就可以了
#include<bits/stdc++.h> using namespace std; const int INF = (1 << 30); const int N = 100000 + 5; const double eps = 1e-8; const int M = 100 + 5; const int MOD = 1e9; char str[N]; int main(){ scanf("%s", str); int len = strlen(str); for(int i = 0; i < len; i += 2) putchar(str[i]); puts(""); }
C:只要考虑a[i+1] + a[i] + a[i+2]就可以了
#include<bits/stdc++.h> using namespace std; const int INF = (1 << 30); const int N = 100000 + 5; const double eps = 1e-8; const int M = 100 + 5; const int MOD = 1e9; int a[N]; int main(){ int n, ans = 0, x, maxn = 0; scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%d", &x); ++ a[x]; if(x > maxn) maxn = x; } for(int i = 0; i <= maxn; i++) ans = max(ans, a[i] + a[i + 1] + a[i + 2]); printf("%d\n", ans); }
D:没想到这么直接,直接swap就行了,我以为有什么套路结果卡着半天,最后还剩3分钟的时候直接交上去竟然AC了。。。神奇。。。
#include<bits/stdc++.h> using namespace std; const int INF = (1 << 30); const int N = 100000 + 5; const double eps = 1e-8; const int M = 100 + 5; const int MOD = 1e9; int a[N]; int main(){ int n, ans = 0; scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 1; i < n; i++) if(a[i] == i) swap(a[i], a[i + 1]), ans++; if(a[n] == n) ans++; printf("%d\n", ans); }