bzoj 1188
博弈的题目做的还是太少啦。。。 不会写啊啊啊
思路:将每个石子看成一个游戏, 那么整个游戏sg值就是全部石子sg值的异或。
1 #include<bits/stdc++.h> 2 #define LL long long 3 #define fi first 4 #define se second 5 #define mk make_pair 6 #define pii pair<int,int> 7 #define piii pair<int, pair<int,int>> 8 9 using namespace std; 10 11 const int N=1e5 + 7; 12 const int M=1e4 + 7; 13 const int inf = 0x3f3f3f3f; 14 const LL INF = 0x3f3f3f3f3f3f3f3f; 15 const int mod = 1e9 + 7; 16 const double eps = 1e-10; 17 const double PI = acos(-1); 18 19 int n, a[22], sg[22], mark[500]; 20 21 int getSg(int x) { 22 if(sg[x] != -1) return sg[x]; 23 memset(mark, 0, sizeof(mark)); 24 for(int i = 0; i < x; i++) { 25 for(int j = 0; j <= i; j++) { 26 mark[getSg(i) ^ getSg(j)] = 1; 27 } 28 } 29 for(int i = 0; ; i++) 30 if(!mark[i]) return sg[x] = i; 31 } 32 int main() { 33 memset(sg, -1, sizeof(sg)); 34 sg[0] = 0; 35 for(int i = 1; i <= 21; i++) { 36 sg[i] = getSg(i); 37 } 38 int T; scanf("%d", &T); 39 while(T--) { 40 scanf("%d", &n); 41 int ans = 0; 42 for(int i = 0; i < n; i++) { 43 scanf("%d", &a[i]); 44 a[i] %= 2; 45 ans ^= a[i] * sg[n - i - 1]; 46 } 47 int tot = 0; 48 for(int i = 0; i < n; i++) { 49 for(int j = i + 1; j < n; j++) { 50 for(int k = j; k < n; k++) { 51 if(!(ans ^ sg[n - i - 1] ^ sg[n - j - 1] ^ sg[n - k - 1])) { 52 if(++tot == 1) printf("%d %d %d\n", i, j, k); 53 } 54 } 55 } 56 } 57 if(!tot) puts("-1 -1 -1"); 58 printf("%d\n", tot); 59 } 60 return 0; 61 } 62 /* 63 */