这是一道Nim博弈;
这要要考虑就是全是1的情况;
View Code
1 #include2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 int main( ) 8 { 9 int n,m,num;10 while( scanf( "%d",&n )==1 )11 {12 while( n-- )13 {14 scanf( "%d",&m );15 int t=0,flag = 0;16 while( m-- )17 {18 scanf( "%d",&num );19 if( num > 1 ) flag=1;20 t ^= num; 21 } 22 if( flag )23 {24 if( t ) printf( "John\n" );25 else puts( "Brother" ); 26 } 27 else28 {29 if( t ==1 ) printf( "Brother\n" );30 else printf( "John\n" ); 31 }32 } 33 }34 //system( "pause" );35 return 0;36 }