zoj2083 Win the Game-----博弈 一排石子分成若干堆

Win the Game

Time Limit: 2 Seconds      Memory Limit: 65536 KB

A and B play a game. There are n lines. A and B color them by turns (A first). One can only color a segment of a line, with length 2, which has not be colored, and the distance between a segment end point and the line's end point is a interger. When one can not color, he loses.


Input

There are several test cases. The first line of a case is a positive interger n, the next line contain n positive intergers, represent the lengths of the n lines. The sum of the lengths do not exceed 50.


Output

If A can win output a "Yes", else output a "No".

Note: you should consider A and B a clever enough.


Sample Input

2
2 4
1
9


Sample Output

Yes
No

 

水题~

#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<memory.h>
using namespace std;
int sg[55];
int dfs(int x)
{
    if(x<2) return sg[x]=0;
    if(sg[x]!=-1) return sg[x];
    bool g[1010]={0};
    for(int i=x-2;i>=0;i--)
    {
        int t=dfs(i)^dfs(x-i-2);
        g[t]=1;
    }
    for(int i=0;;i++)
    if(g[i]==0) return sg[x]=i;
}
int main()
{
    memset(sg,-1,sizeof(sg));
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int num;
        int ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&num);
            ans^=dfs(num);
        }
        if(ans) puts("Yes");
        else puts("No");
    }
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值