poj 3480 John 简单的nim博弈

来源:互联网 发布:opengl shader编程 编辑:程序博客网 时间:2024/06/06 05:32

John

(1) 超过1的个数为2 然后异或值!=0 先者胜,若为0则后者胜 直接按nim来

(2)超过1的个数为1个 然后先者胜

(3)超过1的个数没有,都为1的话,奇数个是后者胜,偶数时先者胜

#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>int main(){    int x;    scanf("%d",&x);    while(x--){                   int n;        scanf("%d",&n);        int aboveOne=0,num,tmp;        scanf("%d",&num);        if(num>1)aboveOne++;        for(int i=2;i<=n;i++){           scanf("%d",&tmp);           if(tmp>1)aboveOne++;           num=num^tmp;                }               if(aboveOne>=2){            if(num!=0)printf("John\n");            else printf("Brother\n");        }        if(aboveOne==1){           printf("John\n");                        }        if(aboveOne==0){           if(n%2==1)printf("Brother\n");           else printf("John\n");                        }           }    return 0;    }