HDU 1907 John 与 poj 3480

这是一道Nim博弈;

这要要考虑就是全是1的情况;

View Code
 1 #include<cstdio>

 2 #include<cstring>

 3 #include<cstdlib>

 4 #include<cmath>

 5 #include<algorithm>

 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             else

28             {

29                 if( t ==1 ) printf( "Brother\n" );

30                 else printf( "John\n" );    

31             }

32         }       

33     }

34     //system( "pause" );

35     return 0;

36 }

 

你可能感兴趣的:(poj)