A. Letter Song ~ 致十年后的我们
处理出来年份,\(+10\) 后输出
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include <bits/stdc++.h> using namespace std;string s; int main () { cin >> s; int x = 0 ; for (int i = 0 ; i < 4 ; i++) x = x * 10 + s[i] - '0' ; x += 10 ; cout << x; for (int i = 4 ; i < s.size (); i++) cout << s[i]; return 0 ; }
B. 简单图形问题 - 0123
手动模拟可以发现,边长为整数的等边三角形面积不可能是整数,因此只需要判断 \(s\) 是否是平方数即可
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include <bits/stdc++.h> #define int long long using namespace std;int T;int s;signed main () { cin >> T; while (T--) { cin >> s; int l = 1 , r = s; while (l < r) { int mid = l + r >> 1 ; if (mid * mid < s) l = mid + 1 ; else r = mid; } int res = l * l == s? 0 : 3 ; cout << res << endl; } return 0 ; }
C. 小红的机器人构造 - Ⅰ+Ⅱ+Ⅲ
组合数学
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 #include <bits/stdc++.h> #define int long long using namespace std;const int N = 100010 , mod = 1e9 + 7 ;int T;int n, x, y;string s; int f[N], g[N];int qmi (int a, int b) { int res = 1 ; while (b) { if (b & 1 ) res = res * a % mod; a = a * a % mod; b >>= 1 ; } return res; } void init () { f[0 ] = g[0 ] = 1 ; for (int i = 1 ; i < N; i++) { f[i] = f[i - 1 ] * i % mod; g[i] = g[i - 1 ] * qmi (i, mod - 2 ) % mod; } } int C (int a, int b) { if (a < b) return 0 ; return f[a] * g[b] % mod * g[a - b] % mod; } signed main () { init (); cin >> T; while (T--) { cin >> n >> x >> y; cin >> s; string t; int a = 0 , b = 0 , c = 0 , d = 0 , c1 = 0 , c2 = 0 ; for (int i = 0 ; i < n; i++) { if (s[i] == 'U' ) { a++; if (x > 0 && c1 < x) t += s[i], c1++; } if (s[i] == 'D' ) { b++; if (x < 0 && c1 > x) t += s[i], c1--; } if (s[i] == 'L' ) { c++; if (y < 0 && c2 > y) t += s[i], c2--; } if (s[i] == 'R' ) { d++; if (y > 0 && c2 < y) t += s[i], c2++; } } if (c1 != x || c2 != y) { cout << "NO" << endl; continue ; } int ca = 0 , cb = 0 , cc = 0 , cd = 0 ; if (x > 0 ) ca = x; if (x < 0 ) cb = -x; if (y < 0 ) cc = -y; if (y > 0 ) cd = y; int r1 = 0 , r2 = 0 ; for (int i = 0 ; i <= min (a - ca, b - cb); i++) r1 = (r1 + C (a, i + ca) * C (b, i + cb) % mod) % mod; for (int i = 0 ; i <= min (c - cc, d - cd); i++) r2 = (r2 + C (c, i + cc) * C (d, i + cd) % mod) % mod; int res = r1 % mod * r2 % mod; cout << "YES" << ' ' << t << ' ' << res << endl; } return 0 ; }
D. 小红的差值构造 - easy+hard+extreme
手玩可以发现,对于 \(x,y\) 的构造,只有两种情况:
\(l>n\) ,不难发现,\(x\) 在 \([1,n]\) 中间位置时,\(\sum_{i=1}^{n}f_i\) 的值最小
\(l<=n\) ,不论 \(x,y\) 取何值,\(\sum_{i=x+1}^{y-1}f_i\) 的值都是不变的,因此只需考虑两边,显然,当\([1,x]\) ,与 \([y+1,n]\) 的长度接近时,答案最小
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include <bits/stdc++.h> #define int long long using namespace std;int T;int n, l;signed main () { cin >> T; while (T--) { cin >> n >> l; int res, x, y; if (l > n) { x = (n + 1 ) / 2 , y = x + l; res = x * (x - 1 ); if (n % 2 == 0 ) res += x; } else { int t = l / 2 ; res = t * (t + 1 ); if ((l - 1 ) % 2 ) res -= t; x = (n - l + 1 ) / 2 , y = x + l; if (x >= 1 ) res += x * (x - 1 ) / 2 ; if (y <= n) res += (n - y) * (n - y - 1 ) / 2 ; } cout << x << ' ' << y << ' ' << res << endl; } return 0 ; }