/* * @Author: Tifa * @Description: From <https://github.com/Tiphereth-A/CP-archives> * !!! ATTENEION: All the context below is licensed under a * GNU Affero General Public License, Version 3. * See <https://www.gnu.org/licenses/agpl-3.0.txt>. */ #include<iostream> usingnamespace std; intgcd(int a, int b){ return b == 0 ? a : gcd(b, a % b); } constint X = 20, Y = 21; intmain(){ int ans = X + Y; for (int x = 1; x < X; ++x) for (int y = 1; y < Y; ++y) if (gcd(x, y) == 1) ans += 2 * ((X - x) * (Y - y) - (X >= 2 * x && Y >= 2 * y) * (X - 2 * x) * (Y - 2 * y)); cout << ans; return0; }
/* * @Author: Tifa * @Description: From <https://github.com/Tiphereth-A/CP-archives> * !!! ATTENEION: All the context below is licensed under a * GNU Affero General Public License, Version 3. * See <https://www.gnu.org/licenses/agpl-3.0.txt>. */ #include<cstring> #include<iostream> usingnamespace std; #define _for(i, l, r) for (int i = l; i <= r; ++i) #define _rfor(i, r, l) for (int i = r; i >= l; --i) constint N = 105, W = 1e5 + 5; int w[N]; bool f[W]; intmain(){ f[0] = 1; int n; cin >> n; int sum = 0; _for(i, 1, n) { cin >> w[i]; sum += w[i]; } int ans = 0; _for(i, 1, n) _rfor(j, sum, w[i]) f[j] |= f[j - w[i]]; _for(i, 1, n) _for(j, 1, sum - w[i]) f[j] |= f[j + w[i]]; _for(i, 1, sum) ans += f[i]; cout << ans; return0; }
G - 异或数列
解题思路
考虑从高到低考虑每个二进制位,如果某个二进制位上已经可以决出胜负,则结束;如果每一位都是平局则平局
所以问题中 \(X_i\) 的取值可简化为 \(\{0,1\}\)
接下来我们考虑 DP
令 \(f(i,j,a,b)\) 表示还剩 \(i\) 个 \(0\), \(j\) 个 \(1\), Alice 为 \(a\), Bob 为 \(b\) 时的结果,则
/* * @Author: Tifa * @Description: From <https://github.com/Tiphereth-A/CP-archives> * !!! ATTENEION: All the context below is licensed under a * GNU Affero General Public License, Version 3. * See <https://www.gnu.org/licenses/agpl-3.0.txt>. */ #include<bits/stdc++.h> usingnamespace std; #define _for(i, l, r) for (auto i = (l); i <= (r); ++i) #define _rfor(i, r, l) for (auto i = (r); i >= (l); --i) constint N = 2e5 + 5; int x[N]; intmain(){ int kase; scanf("%d", &kase); while (kase--) { int n; scanf("%d", &n); _for(i, 1, n) scanf("%d", x + i); int state = 0; _rfor(i, 20, 0) { int now = 1 << i; int cnt = 0; _for(i, 1, n) cnt += !!(x[i] & now); if (!(cnt & 1)) continue; state = ((n - cnt) & 1) && (cnt != 1) ? -1 : 1; break; } printf("%d\n", state); } }