Be the Winner HDU - 2509(反博弈。。这样叫应该没错吧。。)

就是   好几堆苹果  每堆苹果排成一条线  可以任意从每堆拿苹果   如果一堆苹果里拿了之后  则有两种情况  

1、从不是边缘拿   拿完这一堆变成两堆

2、从边缘拿   拿完还是一堆

题目还要求 谁拿最后一堆 谁输。。这种类型的分析看这个吧   https://www.cnblogs.com/WTSRUVF/p/9339499.html

看着其他人直接异或。。我还是练一下sg吧。。。。

#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];
int w;
void mex()
{
    mem(sg, 0);
    bool vis[maxn];
    for(int i=1; i<=w; i++)
    {
        mem(vis, 0);
        for(int j=1; j<=i; j++)
        {
            vis[sg[i-j]] = 1;
            int tot = i-j;
            for(int k=1; k<tot; k++)
                vis[sg[k]^sg[tot-k]] = 1;
        }
        for(int j=0; ; j++)
            if(!vis[j])
            {
                sg[i] = j;
                break;
            }
    }
}

int main()
{
    int n;
    while(cin>> n)
    {
        int cnt = 0, res = 0;
        for(int i=0; i<n; i++)
        {
            cin>> w;
            mex();
            res ^= sg[w];
            if(w == 1) cnt++;
        }
        if(res && cnt != n)
            cout<< "Yes" <<endl;
        else if(!res && cnt == n)
            cout<< "Yes" <<endl;
        else
            cout<< "No" <<endl;

    }

    return 0;
}

猜你喜欢

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