这是一道博弈论问题,典型的Anti-Nim问题。
在Anti-Nim问题中,先手必胜当且仅当:
1、所有堆的石子数都为1且游戏的SG值为0;
2、有些堆的石子数大于1且游戏的SG值不为0。
详见2009年国家集训队论文贾志豪论文
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,d,one,sg;
int main()
{
scanf("%d",&n);
while(n--)
{
one=1;
sg=-1;
scanf("%d",&m);
while(m--)
{
scanf("%d",&d);
if(d!=1)
one=0;
if(sg==-1)
sg=d;
else
sg^=d;
}
if(one&&sg==0)
printf("John\n");
else
if(!one&&sg)
printf("John\n");
else
printf("Brother\n");
}
return 0;
}