分析:Anti-SG游戏。直接套SJ定理就好了(参见贾志豪论文《组合游戏略述——浅谈SG游戏的若干拓展即变形》Chapter.2)
代码:
c++
#include <iostream>
#include <algorithm>
using namespace std;
int t,n,a;
int main(){
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>n;
int max_SG=0;
int res=0;
while(n--){
cin>>a;
res^=a;
max_SG=max(max_SG,a);
}
if(res){
cout<<(max_SG>1?"John":"Brother")<<endl;
}
else{
cout<<(max_SG>1?"Brother":"John")<<endl;
}
}
return 0;
}
python
def main:
t=int(input())
for i in range(0,t):
max_SG=0
res=0
n=int(input())
for i in range(0,n):
a=int(input())
res^=a
if max_SG<a:
max_SG=a
if res:
if max_SG>1:
print('John\n')
else:
print('Brother\n')
else:
if max_SG>1:
print('Brother\n')
else:
print('John\n')
if __name__=='__main__':
main()