这道题和Nim游戏很像,但是条件反了过来:谁取走最后一个石子谁就输。于是就叫反Nim游戏。。。
当所有堆的石子数均为1且有偶数堆/至少有1堆石子数>1且石子数的异或和>0时,先手必胜。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t,n;
int main(){
scanf("%d",&t);
while (t--){
scanf("%d",&n);
int t=0,x=0; bool flag=false;
for (int i=1;i<=n;i++){
scanf("%d",&x);
if (x>1) flag=true;
t^=x;
}
if ((flag&&t)||(!flag&&!t)) printf("John\n");
else printf("Brother\n");
}
return 0;
}