码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj 1022 小约翰的游戏John

时间:2017-12-01 17:15:21      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:bool   for   abd   iostream   include   取石子   ring   get   efi   

题目大意:

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

 

bzoj 1022 小约翰的游戏John

标签:bool   for   abd   iostream   include   取石子   ring   get   efi   

原文地址:http://www.cnblogs.com/yyc-jack-0920/p/7943331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!