Acm hdu 1907 John (game)

Source: Internet
Author: User
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 ;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.