題解:注意題目中規定取到最後一粒石子的人算輸,所以是Anti-Nim遊戲,勝負判斷為:
先手必勝:
1.所有堆的石子數都為1且遊戲的SG值為0;
2.有些堆的石子數大於1且遊戲的SG值不為0。
#include <cstdio>
int main(){
int t,n,s,x,tmp;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(s=tmp=0;n--;)scanf("%d",&x),s^=x,tmp|=(x>1);
puts((s>0)^tmp?"Brother":"John");
}
return 0;
}