1408: The Game
时间限制: 1 Sec 内存限制: 256 MB提交: 72 解决: 36
[ 提交][ 状态][ 讨论版]
题目描述
John and his brother are playing a game. There are several piles of stones. At first John has to pick up some stones from one pile. Then his brother has to make a turn. And so on. Everyone has to pick up at least one stone during his turn. If John (or his brother) will pick up the last stone, he will be considered as a looser.
Both of players are using optimal game strategy. John starts first always.
输入
The first line of input contains a single integer T (1<= T <= 400) indicating the number of test cases. Each test case starts with number N of piles (1<= N <= 47). Then the next line will contain N integers Si (1<= Si <= 4700), separated by spaces – amount of stones of i-th pile.
输出
Output "Jhon" if Jhon win the game, output "Brother" in other case
样例输入
2
3
3 5 1
1
1
样例输出
John
Brother
提示
来源
//neu1408
#include<iostream>#include<cmath>
#include<cstring>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<map>
const int MAX=0xfffffff;
using namespace std;
int main( )
{
// freopen("1.txt","r",stdin);
int t;
while(cin>>t)
{
while(t--)
{
int n;
cin>>n;
int num=0;
int num1=0;
int num2=0;
while(n--)
{
int t;
cin>>t;
num^=t;
if(t==1)
num1++;
else
num2++;
}
if(num&&num2) //S2,S1态,必胜
cout<<"John"<<endl;
else if(!num2&&!num1%2) //T0态必胜
cout<<"John"<<endl;
else
cout<<"Brother"<<endl;
}
}
return 0;
}
1408: The Game
时间限制: 1 Sec 内存限制: 256 MB提交: 72 解决: 36
[ 提交][ 状态][ 讨论版]
题目描述
John and his brother are playing a game. There are several piles of stones. At first John has to pick up some stones from one pile. Then his brother has to make a turn. And so on. Everyone has to pick up at least one stone during his turn. If John (or his brother) will pick up the last stone, he will be considered as a looser.
Both of players are using optimal game strategy. John starts first always.
输入
The first line of input contains a single integer T (1<= T <= 400) indicating the number of test cases. Each test case starts with number N of piles (1<= N <= 47). Then the next line will contain N integers Si (1<= Si <= 4700), separated by spaces – amount of stones of i-th pile.
输出
Output "Jhon" if Jhon win the game, output "Brother" in other case
样例输入
2
3
3 5 1
1
1
样例输出
John
Brother
提示