BZOJ 1022 小约翰的游戏(anti-sg)

这是个anti-sg问题,套用sj定理即可解。

SJ定理

对于任意一个Anti-SG游戏,如果定义所有子游戏的SG值为0时游戏结束,先手必胜的条件: 
1、游戏的SG值为0且所有子游戏SG值均不超过1。 
2、游戏的SG值不为0且至少一个子游戏SG值超过1。

 

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-3
# define MOD 1000000007
# define INF (LL)1<<60
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
    int res=0, flag=0;
    char ch;
    if((ch=getchar())=='-') flag=1;
    else if(ch>='0'&&ch<='9') res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')  res=res*10+(ch-'0');
    return flag?-res:res;
}
void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
const int N=105;
//Code begin...
 
int main ()
{
    int T, n, x;
    scanf("%d",&T);
    while (T--) {
        int ans=0, flag=0;
        scanf("%d",&n);
        FOR(i,1,n) {
            scanf("%d",&x);
            ans^=x;
            if (x>1) flag=1;
        }
        if ((flag==0&&ans==0)||(flag&&ans)) puts("John");
        else puts("Brother");
    }
    return 0;
}
View Code

 

posted @ 2017-03-01 15:37  free-loop  阅读(127)  评论(0编辑  收藏  举报