John
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.
Constraints:
1 <= T <= 474,
1 <= N <= 47,
1 <= Ai <= 4747
2 3 3 5 1 1 1
John Brother
分为两种情况:
1 每个盒子里都只有一颗巧克力;
2 至少有一个盒子的巧克力数量大于一。
对于1情况,若是奇数个盒子,那么John输,否则John赢。
对于2情况,则是尼姆博弈。
#include<cstdio>
int main()
{
int T,N,x,tmp,flag;
scanf("%d",&T);
while(T--)
{
tmp=0;
flag=0;
scanf("%d",&N);
while(N--)
{
scanf("%d",&x);
tmp^=x;
if(x>1)
flag=1;
}
if(flag==1)
{
if(tmp==0)
printf("Brother\n");
else
printf("John\n");
}
else
{
if(tmp!=0)
printf("Brother\n");
else
printf("John\n");
}
}
return 0;
}
583



被折叠的 条评论
为什么被折叠?



