博弈的游戏,先手必赢与后手必赢
package acm.hdu.tests;
import java.io.BufferedInputStream;
import java.util.Scanner;
public class HDU_1907 {
public static void main(String[] args) {
int t,n,flag,sum,i;
int[] a = new int[48];
Scanner console = new Scanner(new BufferedInputStream(System.in));
t = console.nextInt();
while(t-- > 0){
n = console.nextInt();
sum = 0;
flag = 0;
for(i = 0; i < n; i++){
a[i] = console.nextInt();
sum += a[i];
}
if(sum == n){
if(sum%2==0)
System.out.println("John");
else
System.out.println("Brother");
}
else
{
for(i=0;i<n;i++)
flag=flag^a[i];
if(flag==0)
System.out.println("Brother");
else
System.out.println("John");
}
}
}
}