7 条题解
-
0
[AGC002E] Candy Piles
#include <bits/stdc++.h> using namespace std; int n; int a[112345]; bool cmp(int a, int b) { return a > b; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1, cmp); int x = 1; while (a[x + 1] >= x + 1) x++; int h = a[x] - x, w; for (w = 0; a[x + w + 1] == x; w++) ; if (h % 2 || w % 2) cout << "First\n"; else cout << "Second\n"; return 0; }
-
0
P2575 高手过招
#include <bits/stdc++.h> using namespace std; int T; int n; int m[1005]; bool a[1005][25]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> T; while (T--) { cin >> n; //清空棋盘 for (int i = 1; i <= n; i++) for (int j = 1; j <= 20; j++) a[i][j] = false; //输入棋子,每行跑一遍 int sgAll = 0; for (int i = 1; i <= n; i++) { cin >> m[i]; for (int j = 1; j <= m[i]; j++) { int x; cin >> x; a[i][x] = true; } // gao int now = 0; //当前阶梯棋子数 int step = 20 - m[i]; //当前是第几级阶梯 int sgNow = 0; for (int j = 1; j <= 20; j++) { if (a[i][j]) now++; else { if (step % 2 == 1) sgNow ^= now; now = 0; step--; } } sgAll ^= sgNow; } if (sgAll) cout << "YES\n"; else cout << "NO\n"; } return 0; }
-
0
P4576 [CQOI2013]棋盘游戏
#include <bits/stdc++.h> using namespace std; int n, r1, c1, r2, c2; int f[2][20 * 3 + 5][21][21][21][21]; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; int dfs(bool lead, int step, int x, int y, int xx, int yy) { if (f[lead][step][x][y][xx][yy] != -1) return f[lead][step][x][y][xx][yy]; if (step >= 3 * n) return f[lead][step][x][y][xx][yy] = 3 * n; if (x == xx && y == yy) return f[lead][step][x][y][xx][yy] = (lead ? 0 : 3 * n); int now; if (lead) { now = -1; for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 1 || nx > n || ny < 1 || ny > n) continue; now = max(now, dfs(0, step + 1, nx, ny, xx, yy)); } } else { now = 3 * n; for (int i = 0; i < 4; i++) { for (int j = 1; j <= 2; j++) { int nx = xx + j * dx[i], ny = yy + j * dy[i]; if (nx < 1 || nx > n || ny < 1 || ny > n) continue; now = min(now, dfs(1, step + 1, x, y, nx, ny)); } } } return f[lead][step][x][y][xx][yy] = now + 1; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> r1 >> c1 >> r2 >> c2; memset(f, -1, sizeof(f)); if (abs(r1 - r2) + abs(c1 - c2) == 1) cout << "WHITE 1\n"; else cout << "BLACK " << dfs(1, 0, r1, c1, r2, c2) << "\n"; return 0; }
-
0
P3185 [HNOI2007]分裂游戏
#include <bits/stdc++.h> using namespace std; int T; int n; int a[25]; int sg[25]; bitset<64> vis; int main() { ios::sync_with_stdio(false); cin.tie(0); // getSG sg[0] = sg[1] = 0; for (int i = 2; i <= 21; i++) { vis.reset(); for (int j = i - 1; j >= 1; j--) for (int k = j; k >= 1; k--) { vis.set(sg[j] ^ sg[k]); } // sg[i] = mex{sg[j] xor sg[k], i>j>=k} for (int j = 0; j <= 63; j++) if (!vis[j]) { sg[i] = j; break; } } /* for (int i = 1; i <= 21; i++) cout << sg[i] << " "; cout<<"\n"; */ cin >> T; while (T--) { cin >> n; int sgSum = 0; for (int i = n; i >= 1; i--) { cin >> a[i]; if (a[i] % 2) sgSum ^= sg[i]; } if (!sgSum) cout << "-1 -1 -1\n0\n"; else { bool flag = false; int ansi, ansj, ansk, ansCnt = 0; for (int i = n; i > 1; i--) if (a[i]) { int now = sgSum ^ sg[i]; for (int j = i - 1; j >= 1; j--) { for (int k = j; k >= 1; k--) { if (!(now ^ sg[j] ^ sg[k])) { if (!flag) { ansi = n - i; ansj = n - j; ansk = n - k; flag = true; } ansCnt++; } } } } cout << ansi << " " << ansj << " " << ansk << "\n" << ansCnt << "\n"; } } return 0; }
-
0
P2734 [USACO3.3]游戏 A Game
#include <bits/stdc++.h> using namespace std; int n; int a[105]; int sum[105]; int f[105][105]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; f[i][i] = a[i]; } for (int len = 2; len <= n; len++) { for (int i = 1, j = i + len - 1; j <= n; i++, j++) { f[i][j] = max(a[i] + sum[j] - sum[i] - f[i + 1][j], a[j] + sum[j - 1] - sum[i - 1] - f[i][j - 1]); } } cout << f[1][n] << " " << sum[n] - f[1][n] << "\n"; return 0; }
-
0
P1247 取火柴游戏
#include <bits/stdc++.h> using namespace std; int n, xSum; int a[512345]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; xSum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; xSum ^= a[i]; } if (xSum == 0) cout << "lose\n"; else { for (int i = 1; i <= n; i++) { if (a[i] >= (a[i] ^ xSum)) { cout << a[i] - (a[i] ^ xSum) << " " << i << "\n"; a[i] = (a[i] ^ xSum); break; } } for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << "\n"; } return 0; }
-
0
P2197 【模板】nim 游戏
#include <bits/stdc++.h> using namespace std; int T; int n; int xorSum, x; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> T; while (T--) { cin >> n; xorSum = 0; for (int i = 1; i <= n; i++) { cin >> x; xorSum ^= x; } if (xorSum == 0) cout << "No\n"; else cout << "Yes\n"; } return 0; }
- 1
信息
- ID
- 1284
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 10
- 已通过
- 10
- 上传者