BZOJ1022 [SHOI2008] Little John's game John

Source: Internet
Author: User

Description

Little John often plays a very interesting game with his brother: there are n heaps of stones on the table, and Little John and his brother take the stones in turn, and everyone takes
, you can choose a heap of stones at random, in this heap of stones to take away any number of stones, but not a stone nor take, we stipulate to take the last
The man with the stone is counted as a loser. Little John is very stubborn, he insists that the first person has a great advantage, so he always take the stone first, and his brother is smart
More, he never made mistakes in the game. John asked you to be his adviser before he was angry. Naturally, you should first write a program that predicts
Who will win the game.

Input

The input of the subject consists of multiple sets of data the first line consists of an integer t, which indicates that the input has a total of T-group data (t≤500). First line of data for each set of packets
Contains an integer n (n≤50), which represents a total of n heap stones, followed by N of no more than 5000 integers, respectively, representing the number of stones per heap.

Output

The output of each group of data takes one row, and each line outputs a word. If John can win the game, output "John", otherwise output "Brother"
, note the case of the word.

Sample Input2
3
3 5 1
1
1Sample OutputJohn
BrotherHINTSource

Seerc2007

  Positive solutions: Game theoryProblem Solving Report:The game theory naked question, Jia Zhihao's thesis has already spoken this model, no longer repeat. only if not all 1 and SG is not 0 or all 1 and SG is 0, there will be a winner (that will allow the other side to take the last one).   
1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - using namespacestd; -typedefLong LongLL; the intN,X,SG; - BOOLFlag; -  -InlineintGetint () + { -        intw=0, q=0;CharC=GetChar (); +         while((c<'0'|| C>'9') && c!='-') C=getchar ();if(c=='-') q=1, c=GetChar (); A         while(c>='0'&& c<='9') w=w*Ten+c-'0', C=getchar ();returnQ? -w:w; at } -  -InlinevoidWork () { -     intt=getint (); -      while(t--) { -N=getint (); flag=false; sg=0; for(intI=1; i<=n;i++) {x=getint (); Sg^=x;if(x>1) flag=1; }  in     if((flag==false&&sg==0) || (flag==true&&SG>0)) printf ("John");Elseprintf"Brother"); -printf"\ n"); to     } + } -  the intMain () * { $ Work ();Panax Notoginseng   return 0; -}

BZOJ1022 [SHOI2008] Little John's game 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.