Question link:
PKU: http://poj.org/problem? Id = 3480
HDU: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1907
Description
Little 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.
Input
The first line of input will contain a single integerT-The number of test cases. NextTPairs of lines will describe tests in a following format. The first line of each test will contain an integerN-The amount of different M & M colors in a box. Next line will containNIntegersAI, Separated by spaces-amount of M & MsI-Th color.
Constraints:
1 <= t <= 474,
1 <= n <= 47,
1 & lt; = ai & lt; = 4747
Output
OutputTLines each of them containing information about game winner. Print"John"If John will win the game or"Brother"In other case.
Sample Input
233 5 111
Sample output
JohnBrother
Source
Southeastern Europe 2007
PS:
Nheim game deformation!
The Code is as follows:
# Include <cstdio> # define maxn 5017int main () {int t; int A [maxn]; int N, S, K; scanf ("% d", & T ); while (t --) {S = 0, K = 0; scanf ("% d", & N); For (INT I = 0; I <n; I ++) {scanf ("% d", & A [I]); if (a [I]> 1) K ++; S = s ^ A [I];} if (k = 0) // All is 1 {If (N % 2 = 0) // even number of heap printf ("John \ n "); else printf ("Brother \ n");} else {If (s) printf ("John \ n"); else printf ("Brother \ n ");}} return 0 ;}
Poj 3480 & HDU 1907 John)