洛谷P1288 取数游戏II

题目:https://www.luogu.org/problemnew/show/P1288

分析一下,最优走法就是一下把边权走成0;

所以只要起点到左右最近的两条0边中有一个距离为奇数,则先手必胜,否则必败。

代码如下:

#include<iostream>
#include<cstdio>
using namespace std;
int n,l,r;
bool flag;
int main()
{
    scanf("%d",&n);
    for(int i=1,x;i<=n;i++)
    {
        scanf("%d",&x);
        if(x==0)
        {
            if(!flag)flag=1,l=i-1;
            r=n-i;
        }
    }
    if(l%2==1||r%2==1)
    {
        printf("YES");return 0;
    }
    printf("NO");
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Zinn/p/9069663.html