[HNOI2007]分裂游戏 SG打表博弈
结论:其实每一个巧克力都是一堆石子 它的石子数就是它到队尾的距离
打一个SG表即可
#include<bits/stdc++.h> using namespace std; typedef long long ll; int sg[30]; int num[30]; bool vis[1005]; int main() { sg[0] = 0; for (int i = 1; i <= 25; i++) { memset(vis, 0, sizeof(vis)); for (int j = i - 1; j >= 0; j--) { for (int k = j; k >= 0; k--) { vis[sg[j]^sg[k]] = 1; } } for (int j = 0; j <= 1000; j++) { if (!vis[j]) { sg[i] = j; break; } } } int TNT; scanf("%d", &TNT); while (TNT--) { int ans = 0; int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &num[i]); if (num[i] & 1) { ans ^= sg[n - i - 1]; } } int a1 = -1, b1, c1; int cnt = 0; for (int i = 0; i < n - 1; i++) { if (num[i]) { for (int j = i + 1 ; j < n; j++) { for (int k = j; k < n ; k++) { if ((ans ^ sg[n - i - 1]^ sg[n - j - 1] ^ sg[n - k - 1]) == 0) { cnt++; if (a1 == -1) { a1 = i, b1 = j, c1 = k; } } } } } } if (cnt == 0) { printf("-1 -1 -1\n"); } else { printf("%d %d %d\n", a1, b1, c1); } printf("%d\n", cnt); } }