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.

博弈

 

 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 int main(){
 5     int T;
 6     while(scanf("%d",&T)!=EOF){
 7         while(T--){
 8             int n;
 9             scanf("%d",&n);
10             int i,num=0,sum=0;
11             for(i=1;i<=n;i++){
12                 int a;
13                 scanf("%d",&a);
14                 sum^=a;
15                 if(a!=1)num++;
16             }
17             if((num==0&&sum==0)||(sum!=0&&num>0))printf("John\n");
18             else printf("Brother\n");
19         }
20     }
21     return 0;
22 }
View Code