John
Time Limit: 5000/1000 MS (Java/others) memory limit: 65535/32768 K (Java/Others)
Total submission (s): 831 accepted submission (s): 437
Problem descriptionlittle John is playing very funny game with his younger brother. there is one big box filled with M & Ms of different colors. at first John has to eat several M & Ms of the same color. then his opponent has to make a turn. and so on. please note that each player has to eat least one M & M during his turn. if John (or his brother) will eat the last M & M from the box he will be considered as a looser and he will have to buy a new candy box.
Both of players are using optimal game strategy. John starts first always. You will be given information about M & MS and your task is to determine a winner of such a beautiful game.
Inputthe first line of input will contain a single integer t-the number of test cases. next T pairs of lines will describe tests in a following format. the first line of each test will contain an integer N-the amount of different M & M colors in a box. next line will contain N integers AI, separated by spaces-amount of M & Ms of I-th color.
Constraints:
1 <= t <= 474,
1 <= n <= 47,
1 & lt; = ai & lt; = 4747
Outputoutput t lines each of them containing information about game winner. Print "John" if John will win the game or "Brother" in other case.
Sample input2
3
3 5 1
1
1
Sample outputjohn
Brother
Sourcesoutheastern Europe 2007
Recommendlcy
For more information, see: http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html
Code:
# Include < Stdio. h >
Int A [ 50 ];
Int Main ()
{
Int I, ANS, t, n, temp;
Scanf ( " % D " , & T );
While (T -- )
{
Scanf ( " % D " , & N );
Temp = 0 ; // Lonely heap
For (I = 0 ; I < N; I ++ )
{
Scanf ( " % D " , & A [I]);
If (I = 0 )
Ans = A [I];
Else
Ans = Ans ^ A [I];
If (A [I] > 1 ) Temp = 1 ;
}
If (Temp = 0 )
{
If (N % 2 = 1 )
Printf ( " Brother \ n " );
Else
Printf ( " John \ n " );
Continue ;
}
If (ANS = 0 )
Printf ( " Brother \ n " );
Else
Printf ( " John \ n " );
}
Return 0 ;
}