Little 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.
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 特殊情况 如果全部都是1的话 是偶数的话那么就是先手赢不然就是后者赢
2 就是尼姆博弈 嗯面对奇异局势的话 哪一方都没有办法
代码如下
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int flag=0;
int temp=0,gg;//0和任何东西yi或都是 任何东西
for(int i=1;i<=n;i++)
{
cin>>gg;
temp=temp^gg;
if(gg>1)
flag=1;
}
if(flag)
{
//面对奇异局势那么哪一方都没有办法
if(temp==0)
puts("Brother");
else
puts("John");
}//一下是特殊情况需要具体考虑下
//如果都是1 并且是偶数 那么是先手赢 不然就是后手赢
else
{
if(n%2==1)
puts("Brother");
else
puts("John");
}
}
return 0;
}