对于一个anti-sg游戏(最后操作者输)。可用sj定理解决。
sj定理:
先手必胜的条件:
(1)游戏总的sg值不为0,且某个单一游戏的sg值大于1;
(2)游戏总的sg值为0,且所有单一游戏的sg值小于等于1;
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int sg[maxn],k,q;
int main()
{
int n,m,x;
int a,b;
int T;
cin>>T;
while(T--)
{
cin>>n;
int flag=0,ans=0;
for(int i=0;i<n;i++)
{
cin>>x;
flag^=x;
ans=max(ans,x);
}
if((flag&&ans>1)||(!flag&&ans<=1))
cout<<"John"<<endl;
else cout<<"Brother"<<endl;
}
return 0;
}