HDU 1907 John

來源:互聯網
上載者:User

 

John

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 258    Accepted Submission(s): 130

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 at 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 <= Ai <= 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 Input
233 5 111
 

 

Sample Output
JohnBrother
 

 

SourceSoutheastern Europe 2007  解題:       尼姆博弈。對於N堆的糖,一種情況下是每堆都是1,那麼誰輸誰贏看堆數就知道;對於不都是1的話,若這些堆是奇異局勢,或說他們是非奇異局勢,但非奇異局勢皆可以轉換到奇異局勢(具體轉變看上一篇介紹)。       經典的尼姆問題是誰哪拿到最後一個則誰贏,本題是拿最後一個的輸。下面分析第二種情況:
1.初始給的是奇異局勢的話,則先取者為輸。
2.初始給的是非奇異局勢的話,則先取者為贏。輾轉轉換非奇異、奇異的次數是相對的。#include <iostream><br />using namespace std;</p><p>int main()<br />{<br />int T,N,i,A[50],sum,k;<br />cin>>T;<br />while (T--)<br />{<br />cin>>N;<br />sum=0;k=0;<br />for (i=0;i<N;i++)<br />{<br />cin>>A[i];<br />sum^=A[i];<br />if (A[i]>1)<br />{<br />k=1;<br />}<br />}<br />if (k==0) //對於每堆都是1的情況下<br />{<br />if (N%2==0)<br />{<br />cout<<"John"<<endl;<br />}<br />else<br />{<br />cout<<"Brother"<<endl;<br />}<br />}<br />else<br />{<br />if (sum==0) //對於奇異局勢的情況下<br />{<br />cout<<"Brother"<<endl;<br />}<br />else //對於非奇異局勢的情況下<br />{<br />cout<<"John"<<endl;<br />}<br />}<br />}<br />return 0;<br />}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.