hdu2509 Be the Winner (反尼姆博弈,好题)

题目大意:有n堆苹果,每堆Mi个。两人轮流取,每次可以从一堆苹果中取任意连续个苹果,最后取光者为输。Fra先下,问是否可以获胜。

证明:

需要特别说明一下:S2一定有办法转化为T2。自己稍微试试就明白了

#include<bits/stdc++.h>
using namespace std;
const int N=109;
int a[N];
int main()
{
    int n,i,j,x;
    while(~scanf("%d",&n))
    {
        x=j=0;
        int f;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            x^=a[i];
            if(a[i]>=2)
                j++;
        }
        if(x!=0)
        {
            if(j==0)
                f=1;
            else
                f=2;
        }
        else
        {
            if(j==0)
                f=2;
            else
                f=1;
        }
        if(f==1)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39861441/article/details/89255558