bzoj 1022 小约翰的游戏John

题目大意:

n堆石子,两个人轮流取石子,每个人取的时候,可以随意选择一堆石子

在这堆石子中取走任意多的石子,但不能一粒石子也不取,取到最后一粒石子的人算输

思路:

首先当每堆石子数都为1时,偶数为先手必胜,奇数为先手必败

当有一堆石子数不为1时,先手可以使堆变为奇数个1的堆,即先手必胜

而如果有很多堆石子数不为1,如果异或和不为0,则先手可以把异或和变为0 变为必胜态

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<cstdlib>
 6 #include<cstring>
 7 #include<queue>
 8 #include<map>
 9 #include<vector>
10 #define ll long long
11 #define inf 2147483611
12 #define MAXN 1010
13 using namespace std;
14 inline int read()
15 {
16     int x=0,f=1;char ch=getchar();
17     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
18     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
19     return x*f;
20 }
21 int T,n;
22 int main()
23 {
24     T=read();int sum,a;bool f;
25     while(T--)
26     {    
27         n=read(),sum=f=0;
28         for(int i=1;i<=n;i++)
29         {
30             a=read();
31             sum^=a;
32             if(a!=1) f=1;
33         }
34         if((!f&&!sum)||(sum&&f)) puts("John");
35         else puts("Brother");
36     }
37 }
View Code

 

posted @ 2017-12-01 16:57  jack_yyc  阅读(124)  评论(0编辑  收藏  举报