• 《SG函数练习》


    HDU1848.

    筛出每个值的SG函数值。

    然后根据xxx博弈的定理:多个堆的博弈结果为每个堆结果的异或值。

    为0先手必败,否则先手必胜。

    // Author: levil
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef pair<int,int> pii;
    const int N = 2e5+5;
    const int M = 1e4;
    const LL Mod = 1e9+7;
    #define rg register
    #define pi acos(-1)
    #define INF 1e18
    #define CT0 cin.tie(0),cout.tie(0)
    #define IO ios::sync_with_stdio(false)
    #define dbg(ax) cout << "now this num is " << ax << endl;
    namespace FASTIO{
        inline LL read(){  
            LL x = 0,f = 1;char c = getchar();
            while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
            while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
            return x*f;
        }
        void print(int x){
            if(x < 0){x = -x;putchar('-');}
            if(x > 9) print(x/10);
            putchar(x%10+'0');
        }
    }
    using namespace FASTIO;
    void FRE(){
    /*freopen("data1.in","r",stdin);
    freopen("data1.out","w",stdout);*/}
    
    int f[1005],cnt = 0,SG[1005],S[1005];
    void init()
    {
        f[1] = 1,f[2] = 2,cnt = 2;
        for(rg int i = 3;f[i-1] <= 1000;++i) f[i] = f[i-1]+f[i-2],cnt = i;
        cnt--;
    }
    void slove(int x)
    {
        for(rg int i = 1;i <= x;++i)
        {
            memset(S,0,sizeof(S));
            for(rg int j = 1;j <= cnt && f[j] <= i;++j) S[SG[i-f[j]]] = 1;
            for(rg int j = 0;;++j) if(!S[j]){SG[i] = j;break;}
        }
    }
    int main()
    {
        init();
        slove(1000);
        int m,n,p;
        while(m = read(),n = read(),p = read(),m || n || p)
        {
            LL ma = SG[m]^SG[n]^SG[p];
            if(ma == 0) printf("Nacci
    ");
            else printf("Fibo
    ");
        }
        system("pause");
    }
    View Code

    POJ2234;

    这里可以取任意数量的数。然后还是多堆。

    那么直接将整个数看成SG函数即可。

    // Author: levil
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef pair<int,int> pii;
    const int N = 2e5+5;
    const int M = 1e4;
    const LL Mod = 1e9+7;
    #define rg register
    #define pi acos(-1)
    #define INF 1e18
    #define CT0 cin.tie(0),cout.tie(0)
    #define IO ios::sync_with_stdio(false)
    #define dbg(ax) cout << "now this num is " << ax << endl;
    namespace FASTIO{
        inline LL read(){  
            LL x = 0,f = 1;char c = getchar();
            while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
            while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
            return x*f;
        }
        void print(int x){
            if(x < 0){x = -x;putchar('-');}
            if(x > 9) print(x/10);
            putchar(x%10+'0');
        }
    }
    using namespace FASTIO;
    void FRE(){
    /*freopen("data1.in","r",stdin);
    freopen("data1.out","w",stdout);*/}
    
    int main()
    {
        IO;CT0;
        int m,x;
        while(cin >> m)
        {
            LL ans = 0;
            for(rg int i = 1;i <= m;++i) cin >> x,ans ^= x;
            if(ans == 0) printf("No
    ");
            else printf("Yes
    ");
        }
        system("pause");
    }
    View Code
  • 相关阅读:
    容器优雅关闭方案,进程id为1
    要使vue支持ts写法
    深入理解docker信号机制以及dumbinit的使用
    elselect数据量过大引发卡顿,怎么办?
    @开发者 云端一条生产线,让软件开发更敏捷、更安全
    华为云重磅发布:“乐高式”自动驾驶研发开放平台,携手伙伴共建生态
    SRE,了解一下?35+岁程序员新选择
    开发者能力大赏,谁是技术知识达人?
    极速生成缩略图,Serverless 支撑赛事转播锁定冬奥亮点
    15 分钟实现企业级应用无损上下线
  • 原文地址:https://www.cnblogs.com/zwjzwj/p/13563450.html
Copyright © 2020-2023  润新知