solution1(通过0%)
没看懂怎么是必胜或必败局面(˚ ˃̣̣̥᷄⌓˂̣̣̥᷅ )
#include<iostream>
typedef long long ll;
const int maxn = 200010;
ll x[maxn];
int main(){int t, n;ll a, b, turn;scanf("%d", &t);while(t--){a = b = 0;turn = 1;scanf("%d", &n);for(int i = 1; i <= n; i++){scanf("%lld", x + i);if(turn % 2 == 1){if(a ^ x[i] > b) a ^= x[i];else b ^= x[i];}else{if(b ^ x[i] > a) b ^= x[i];else a ^= x[i];}turn++; }if(a > b) printf("1\n");else if(a == b) printf("0\n");else printf("-1\n");}return 0;
}
solution2
#include<stdio.h>
#include<string.h>
const int d = 21, maxn = 200010;
int main(){int t, n, x, ans, num, cnt, f[d];scanf("%d", &t);while(t--){memset(f, 0, sizeof(f));//初始化计数数组ans = cnt = 0;//默认为平局scanf("%d", &n);for(int i = 0; i < n; i++){num = 0;scanf("%d", &x);while(x){f[num] += x % 2; //统计每位1的个数num++;x /= 2;}if(cnt < num) cnt = num;//最高位位数}for(int i = cnt - 1; i >= 0; i--){//十进制转n进制,高位f[cnt-1],低位f[0]if(f[i] % 2 == 1){//1的个数为奇数个,出现必胜或必败if(f[i] == 1 || n % 2 == 1) ans = 1;//只有1个1或者有偶数个0,一定是先手拿到该1==》先手获胜else ans = -1;break;}}printf("%d\n", ans);}return 0;
}