hdu 2509 Be the Winner

来源:互联网 发布:吉他软件手机版 编辑:程序博客网 时间:2024/05/07 15:18
Let's consider m apples divided into n groups. Each group contains no more than 100 apples, arranged in a line. You can take any number of consecutive apples at one time.For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last isthe loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win).

Input

You will be given several cases. Each test case begins with a single number n (1 <= n <= 100), followed by a line with n numbers, the number of apples in each pile. There is a blank line between cases.

Output

If a winning strategies can be found, print a single line with "Yes", otherwise print "No".

Sample Input

22 213

Sample Output

NoYes

【题意】

给你很多堆苹果,你有两种选择。
1,选择某一堆,干掉任意数量的。
2,如果某一堆的数量多于两个,你可以选择它,然后分成都不为0的两堆。

【分析】

还是Nim博弈,和hdu1907几乎就是换了个输出方式,不多说。

【代码】

#include <cstdio>#include <cstdlib>#include <cstring>#include <map>#include <list>#include <algorithm>#include <iostream>using namespace std;int len;void ans(void){    int a=0,b=1,c;    for(int i=0;i<len;i++)    {        cin>>c;        if(c!=1)            b=0;        a^=c;    }    if(b) cout << ((len&1)?"No":"Yes")<<endl;    else cout<<(a?"Yes":"No")<<endl;}int main() {//    freopen("in.txt","r",stdin);    while(scanf("%d",&len)!=EOF)    {        ans();    }    return 0;}
原创粉丝点击