zoukankan      html  css  js  c++  java
  • P4279 [SHOI2008]小约翰的游戏

    传送门

    显然的 $Anti-SG$ ,直接套上结论就行

    当然也可以略证一下

    $1.$如果石头堆都只有一个石头,那么堆数为偶数时先手必胜

    $2.$如果某堆有多个石头,那么总 $SG$ 不为 $0$ 时先手必胜

    考虑只要一堆有多个石头时,先手可以拿到只剩一个或者全部拿完,然后就变成 $1.$ 的情况并且先手可以随意控制堆的奇偶,先手必胜

    如果有多堆石头且 $SG$ 值不为 $0$ 时,先手显然可以拿成 $SG$ 为 $0$ 的情况,然后后手又不得不拿成 $SG$ 不为 $0$ 的情况...最后 $SG$ 不为 $0$ 的情况一定是只剩一堆有多个石头,然后就到了 $2.$ 的情况

    后手面对非 $1.2.$ 时必输,所以当且仅当 $1.2.$ 其中一条满足时,先手必胜

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    using namespace std;
    typedef long long ll;
    inline int read()
    {
        int x=0,f=1; char ch=getchar();
        while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
        while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
        return x*f;
    }
    int T,n,a,now;
    int main()
    {
        T=read();
        while(T--)
        {
            n=read(); int mx=0; now=0;
            for(int i=1;i<=n;i++)
            {
                a=read(); now^=a;
                mx=max(mx,a);
            }
            if((!now&&mx<=1) || (now&&mx>1)) printf("John
    ");
            else printf("Brother
    ");
        }
        return 0;
    }
  • 相关阅读:
    「CSP-S 2019」树的重心「重心」
    「SDOI2017」天才黑客「优化建图最短路」
    「NOI Online Round2」 题解
    Qt 自定义序列化
    Android 定制化apk生成
    gradle上传jar包到maven公共仓库
    JAVA 插入注解处理器
    使用docker安装gitlab
    数据库递归树形查询优化
    JDBCTemplate使用
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11427599.html
Copyright © 2011-2022 走看看