hdu2509——反nim博弈

题目链接:acm.hdu.edu.cn/showproblem.php?pid=2509

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 is
the 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

2
2 2
1
3

Sample Output

No
Yes

题目翻译:

让我们考虑将苹果分成n组。每组包含不超过100个苹果,排列成一行。一次可以取任意数量的连续苹果。‎
‎例如,"*"可以转换为"*"或"*"或"*"(两堆)。两个人一个接一个地吃苹果,最后一个人是‎
‎失败者。Fra 想知道在什么情况下,他可以通过打策略来获胜(也就是说,无论对手采取什么行动,弗拉都会赢)。‎

‎输入‎

‎你将得到几个案例。每个测试用例以单个数字 n (1 <= n <= 100) 开头,后跟一行带有 n 个数字,即每堆中的苹果数。案例之间有一个空行。‎

‎输出‎

‎如果可以找到获胜策略,则打印一行"是",否则打印"否"。‎

 

取火柴游戏(反尼姆博弈)裸题。

#include
using namespace std;
int main(){int n;while(~scanf("%d",&n)){int cnt=0,sum=0;for(int i=1;i<=n;++i){int x;scanf("%d",&x);sum^=x;if(x>1) cnt++;}if((sum==0&&cnt==0)||(sum!=0&&cnt!=0))printf("Yes\n");else printf("No\n");}return 0;
}

 


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部