阅读背景:

Codeforces Round #617 (Div. 3) A Array with Odd Sum B Food Buying C Yet Another Walking Robot

来源:互联网 
A #include <cstdio> int t, n, num; int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); int odd = 0; for (int i = 1; i <= n; i++) { scanf("%d", &num); if (num & 1) odd++; } if (odd == 0 || (!(odd & 1) && odd == n)) printf("NO\n"); else printf("YES\n"); } return 0; } B #include <cstdio> int t, n; int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); int ans = n; while (n >= 10) { int t = n / 10; ans += t; n += t - t * 10; } printf("%d\n", ans); } return 0; } C 有mp记录每个位置是否被访问过。 如果访问过代表走了个环。 求出走的路径长度。 #include <cstdio> #include <algorithm> #include <map> #define mk(x,y) make_pair(x,y) using namespace std; const int N = 2e5 + 5; char s[N]; int t, n; int main() { scanf("%d", &t); while (t--) { scanf("%d%s", &n, s + 1); map<pair<int, int>, int> mp; mp[mk(0, 0)] = 1; //作为起点 int x = 0, y = 0, l, r, minv = 1e9; for (int i = 1; i <= n; i++) { if (s[i] == 'L') x--; else if (s[i] == 'R') x++; else if (s[i] == 'U') y++; else if (s[i] == 'D') y--; pair<int, int> t = mk(x, y); if (mp.count(t)) { //取个最小值 int d = i - mp[t]; if (d < minv) { minv = d; r = i, l = mp[t]; } } mp[mk(x, y)] = i + 1; //及时更新位置 } if (minv == 1e9) printf("-1\n"); else printf("%d %d\n", l, r); } return 0; } A #include <cstdio> int t, n, num; int main() { s



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: