luogu P4279 [SHOI2008]小约翰的游戏
https://www.luogu.com.cn/problem/P4279
分析一下会发现是nim游戏板子题
SG函数就是每堆的石头数
异或起来即可
注意特判1
code:
#include<bits/stdc++.h>
using namespace std;
int t, n;
int main() {
scanf("%d", &t);
while(t --) {
scanf("%d", &n);
int s = 0, ans = 0;
for(int i = 1; i <= n; i ++) {
int x;
scanf("%d", &x);
s += x, ans ^= x;
}
if(s == n) {
if(!(s & 1)) puts("John");
else puts("Brother");
} else {
if(ans) puts("John");
else puts("Brother");
}
}
return 0;
}