Poj 3480 & HDU 1907 John)

Source: Internet
Author: User

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)

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.