zoukankan      html  css  js  c++  java
  • HDU 5795 A Simple Nim

    打表找SG函数规律。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    inline int read()
    {
        char c = getchar();  while(!isdigit(c)) c = getchar();
        int x = 0;
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
        return x;
    }
    
    int sg[200],f[200];
    
    int main()
    {
        sg[0]=0;
        for(int i=1;i<=100;i++)
        {
            memset(f,0,sizeof f);
    
            for(int j=0;j<i;j++) f[sg[j]]=1;
    
            for(int j=1;j<=i;j++)
            {
                for(int k=1;k<=i;k++)
                {
                    for(int s=1;s<=i;s++)
                    {
                        if(j+k+s!=i) continue;
                        f[sg[j]^sg[k]^sg[s]]=1;
                    }
                }
            }
            for(int j=0;j<200;j++) if(f[j]==0) {sg[i]=j;break;}
        }
        for(int i=0;i<=100;i++) printf("i:%d  sg[i]:%d
    ",i,sg[i]);
        return 0;
    }

    然后就可以轻松AC了...

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    inline int read()
    {
        char c = getchar();  while(!isdigit(c)) c = getchar();
        int x = 0;
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
        return x;
    }
    
    const int maxn=1000000+10;
    int T,n; LL ans,x;
    
    LL SG(LL x)
    {
        if(x==0)return 0; if(x==1) return 1;
        if(x%8==0) return x-1; if((x+1)%8==0) return x+1;
        return x;
    }
    
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n); ans=0;
            for(int i=1;i<=n;i++) scanf("%lld",&x), ans=ans^SG(x);
            if(ans) printf("First player wins.
    ");
            else printf("Second player wins.
    ");
        }
        return 0;
    }
  • 相关阅读:
    蓝桥杯省赛模拟:村庄建设、郊外植树。
    Andrew 算法(构造凸包)
    Codeforces Round #635 (Div. 2)(A, B, C, D)
    级边凸包构造法(extreme edge)
    极点的凸包构造算法(extreme point)
    Codeforces Round #633 (Div. 2)(A, B, C)
    凸包---graham scan算法 + 例题P2742
    Element-ui中ElScrollBar组件滚动条的使用
    HTTP:Web的基础
    HTTP报文
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5741549.html
Copyright © 2011-2022 走看看