AtCoder 比赛笔记(1)
1、AtCoder Beginner Contest 242
A
注意排名在 $B$ 之后就没有 T-shirt 了。
1 int main() 2 { 3 int a, b, c, x; read(a, b, c, x); 4 if (x <= a) printf("%.10lf", 1.0); 5 else if (x > b) printf("%.10lf", 0.0); 6 else printf("%.10lf", (double)c / (b - a)); 7 fwrite(pbuf, 1, pp - pbuf, stdout); return 0; 8 }
B
注意是“by permuting the characters of $S$”,即将 $S$ 的字符进行任意排列,不要看成是只能循环同构。
1 const int N = 2e5 + 10; 2 char s[N]; 3 4 int main() 5 { 6 scanf("%s", s); sort(s, s + strlen(s)); cout << s; 7 fwrite(pbuf, 1, pp - pbuf, stdout); return 0; 8 }
C
直接 DP 即可。
1 const int N = 1e6 + 10; 2 const ll p = 998244353; 3 ll dp[N][10]; 4 5 int main() 6 { 7 int n; read(n); ll ans = 0; 8 for (int j = 1; j <= 9; ++j) dp[1][j] = 1; 9 for (int i = 2; i <= n; ++i) 10 for (int j = 1; j <= 9; ++j) 11 { 12 (dp[i][j] += dp[i - 1][j]) %= p; 13 if (j != 1) (dp[i][j] += dp[i - 1][j - 1]) %= p; 14 if (j != 9) (dp[i][j] += dp[i - 1][j + 1]) %= p; 15 } 16 for (int j = 1; j <= 9; ++j) (ans += dp[n][j]) %= p; cout << ans; 17 fwrite(pbuf, 1, pp - pbuf, stdout); return 0; 18 }
D
先将 $k$ 减 $1$ 后就能显然发现,$k$ 的二进制位是 $0$ 就是变换成第一个字符,$1$ 就是变换成第二个字符。
1 const int N = 1e5 + 10; 2 char s[N]; 3 4 int main() 5 { 6 scanf("%s", s + 1); int q; read(q); 7 while (q--) 8 { 9 ll t, k, x; read(t, k); --k; 10 t >= 60 ? x = 1 : x = 1 + (k >> t); 11 if (x > 1) k -= (x - 1) << t; 12 int ch = s[x] - 'A'; 13 if (t > 60) (ch += (t - 60) % 3) %= 3, t = 60; 14 for (int i = t - 1; ~i; --i) ch += 1 + (k >> i & 1); ch %= 3; 15 pc(ch + 'A'), pc('\n'); 16 } 17 fwrite(pbuf, 1, pp - pbuf, stdout); return 0; 18 }
E
将前缀字符串字典序分成小于和等于两种情况算答案即可。
1 const int N = 1e6 + 10; 2 const ll p = 998244353; 3 int t, n, a[N]; 4 char s[N]; 5 ll b[N]; 6 7 int main() 8 { 9 read(t); b[0] = 1; 10 for (int i = 1; i <= 1000000; ++i) b[i] = b[i - 1] * 26 % p; 11 while (t--) 12 { 13 read(n), read(s + 1); 14 for (int i = 1; i <= n; ++i) a[i] = s[i] - 'A'; 15 int mid = (n - 1 >> 1) + 1; bool flag = true; ll ans = 0; 16 for (int i = 1; i <= mid; ++i) 17 ans = (ans + a[i] * b[mid - i] % p) % p; 18 for (int i = mid + 1; i <= n; ++i) 19 if (a[n - i + 1] < a[i]) break; 20 else if (a[n - i + 1] > a[i]) { flag = false; break; } 21 if (flag) ++ans, ans %= p; 22 print(ans), pc('\n'); 23 } 24 fwrite(pbuf, 1, pp - pbuf, stdout); return 0; 25 }
F
G
裸的普通莫队。
1 const int N = 1e5 + 10, Q = 1e6 + 10; 2 int n, m, B, ans, a[N], pos[N], cnt[N], Ans[Q]; 3 struct query 4 { 5 int l, r, id; 6 inline bool operator < (const query &x) const 7 { 8 return pos[l] != pos[x.l] ? pos[l] < pos[x.l] : pos[l] & 1 ? r < x.r : r > x.r; 9 } 10 } q[Q]; 11 12 inline void add(int x) { if (cnt[x] & 1) ++ans; ++cnt[x]; } 13 inline void del(int x) { --cnt[x]; if (cnt[x] & 1) --ans; } 14 15 int main() 16 { 17 read(n); for (int i = 1; i <= n; ++i) read(a[i]); 18 read(m); B = ceil(sqrt(3) * n / sqrt(m)); 19 for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / B + 1; 20 for (int i = 1; i <= m; ++i) read(q[i].l, q[i].r), q[i].id = i; 21 sort(q + 1, q + m + 1); 22 for (int l = 1, r = 0, i = 1; i <= m; ++i) 23 { 24 while (l > q[i].l) add(a[--l]); 25 while (r < q[i].r) add(a[++r]); 26 while (l < q[i].l) del(a[l++]); 27 while (r > q[i].r) del(a[r--]); 28 Ans[q[i].id] = ans; 29 } 30 for (int i = 1; i <= m; ++i) print(Ans[i]), pc('\n'); 31 fwrite(pbuf, 1, pp - pbuf, stdout); return 0; 32 }
Ex
2、AtCoder Beginner Contest 243
To be continued...