签到水题
代码
#includeusing namespace std; const int N = 110; int n; string st; void solve() { cin >> n >> st; for (int i = 0; i < st.size(); i ++ ) if (st[i] == 'L') printf("L"); else if (st[i] == 'R') printf("R"); else if (st[i] == 'U') printf("D"); else printf("U"); puts(""); } int main() { int t; cin >> t; while (t -- ) { solve(); } return 0; }
B. MEXor Mixup
思维题 分情况讨论
先预处理一下前缀异或和 不然会超时
第一种 如果mex值异或上mex之前的异或和等于xor 则要在mex之前个数上加二
第二种 如果mex之前的异或和等于xor 可以直接输出mex之前个数
除了上面两种 只需要输出mex之前个数加一即可
代码
#includeusing namespace std; const int N = 3e5 + 10; int a, b; int c[N]; inline int read() { register int x = 0, k = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return x * k; } void init() { for (int i = 1; i <= 300005; i ++ ) c[i] = c[i - 1] ^ i; } void solve() { a = read(), b = read(); if (c[a - 1] == b) printf("%dn", a); else if ((c[a - 1] ^ b) == a) printf("%dn", a + 2); else printf("%dn", a + 1); } int main() { int t; t = read(); init(); while (t -- ) { solve(); } return 0; }
C - Carrying Conundrum
思维题 Alice在计算进位的时候要进两位 我们可以发现这样对中间的一位不会产生任何影响 只会对隔位产生影响 所以我们可以吧12345分解为 135和24来求解
注意题中要求分解为的所有数字都是正数 所以我们要把0给去掉 而这种做法会出现两个0 比如0 + 135, 0 + 24 = 00000 + 12345 和 135 + 0, 24 + 0 = 12345 + 00000 所以最终再减去2即可
代码
#includeusing namespace std; string n; int a, b; long long ans; inline int read() { register int x = 0, k = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return x * k; } void solve() { a = 0, b = 0; cin >> n; for (int i = 0; i < n.size(); i ++ ) if (i & 1) a = a * 10 + n[i] - '0'; else b = b * 10 + n[i] - '0'; ans = (a + 1) * (b + 1) - 2; printf("%lldn", ans); } int main() { int t; t = read(); while (t -- ) { solve(); } return 0; }
D - expression evaluation Error
题意为如果把一个十进制数分解为n个数相加 这n个数在分解后会变为11进制 然后这些数在相加最大为多少
我们可以看出 最优的情况一般是不从高位变为地位 即不变位的时候是最优的
我们可以先在m个加数中放入一个1 剩余数为n - m 然后我们再贪心去往每个空里加数 直到不能加为止
代码
#includeusing namespace std; int n, m; inline int read() { register int x = 0, k = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return x * k; } void solve() { n = read(), m = read(); n -= m; for (int i = 0; i < m - 1; i ++ ) { int t = 1; while (t * 10 - 1 <= n) t *= 10; printf("%d ", t); n -= t - 1; } if (n >= 0) printf("%dn", n + 1); } int main() { int t; t = read(); while (t -- ) { solve(); } return 0; }



