1408: The Game
时间限制: 1 Sec 内存限制: 256 MB提交: 54 解决: 25
[ 提交][ 状态][ 讨论版]
题目描述
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
#include<stdio.h>
int main()
{
int a[50];
int T,n,num1,num2,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
ans=num1=num2=0;
for(int i=0;i<n;i++)
{
scanf("%d",a+i);
if(a[i]==1)
num1++;
else
num2++;
ans^=a[i];
}
if((ans&&num2!=0)||(!ans&&num2==0))
printf("John\n");
else
printf("Brother\n");
}
return 0;
}
#include<stdio.h>
int main()
{
int a[50];
int T,n,num1,num2,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
ans=num1=num2=0;
for(int i=0;i<n;i++)
{
scanf("%d",a+i);
if(a[i]==1)
num1++;
else
num2++;
ans^=a[i];
}
if((ans&&num2!=0)||(!ans&&num2==0))
printf("John\n");
else
printf("Brother\n");
}
return 0;
}