A Chess Game HDU - 1524(sg)

因为题中是个环,

所以我们可以首先拿出一组m 

如果n<m 先手必输

否则的话跑sg函数 n = n-m

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;
int sg[maxn], vis[maxn];
int a[maxn];

void init(int n, int m)
{
    mem(sg, 0);
    sg[m] = 1;
    for(int i=m; i<=n; i++)
    {
        mem(vis, 0);
        vis[sg[i-m]] = 1;
        int tot = i-m;
        for(int j=1; j<tot; j++)
            vis[sg[j]^sg[tot-j]] = 1;
        for(int j=0; ; j++)
            if(!vis[j])
            {
                sg[i] = j;
                break;
            }
    }
}

int main()
{
    int T, kase = 0;
    cin>> T;
    while(T--)
    {
        int n, m;
        cin>> n >> m;
        printf("Case #%d: ",++kase);

        if(n < m)
        {
            cout<< "abcdxyzk" <<endl;
            continue;
        }
        init(n-m, m);
        if(sg[n-m])
            cout<< "abcdxyzk" <<endl;
        else
            cout<< "aekdycoin" <<endl;


    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/WTSRUVF/p/9336977.html