题意:转化来就是有 n 个石堆,每回合选一堆取任意个,取完所有石堆中最后一个石子的判负,求必胜方;
代码:Nim博弈,不过之前常规的是取完最后一个判赢,这个变形得知道 SJ 定理,(http://blog.sina.com.cn/s/blog_51cea4040100h3l9.html)
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
int T,n;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int res=0,Max=0;
for(int i=1,x;i<=n;i++){
scanf("%d",&x);
res^=x;
Max=max(Max,x);
}
if(res&&Max>1|| res==0&&Max<=1) puts("John");
else puts("Brother");
}
}