题目描述
题解
Anti-Nim游戏:
先手必胜当且仅当
- 每一堆的石子个数都为1且异或值=0
- 存在某一堆的石子个数>1且异或值 ≠ 0
代码
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int T,n,ans;
int a[50];
int main(){
scanf("%d",&T);
while (T--){
scanf("%d",&n);
ans=0;
bool pd=false;
for (int i=1;i<=n;++i){
scanf("%d",&a[i]);
ans^=a[i];
if (a[i]>1) pd=true;
}
if (!ans&&!pd) puts("John");
else if (ans&&pd) puts("John");
else puts("Brother");
}
}