• 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
  • 相关阅读:
    博客园美化(三)
    博客园美化(二)
    python异常处理
    博客园美化(一)
    STD二手图书交流平台团队博客-用户画像
    STD二手图书交流平台团队博客-电梯演讲
    学习如何运用GitHub网站+出现的问题+Git基本操作总结
    人月神话阅读笔记(二)
    人月神话阅读笔记(一)
    Android studio Handler消息处理1
  • 原文地址:https://www.cnblogs.com/lishiyao/p/6484560.html
Copyright © 2020-2023  润新知