HDU 2509——anti-nim

题目:

Description

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

分析:

anti-nim

 1 #include<cstdio>
 2 int main()
 3 {
 4     int n,a[100],ans,flag;
 5     while(scanf("%d",&n)==1)
 6     {
 7         ans=0;
 8         flag=1;
 9         for(int i=0;i<n;i++)
10         {
11             scanf("%d",&a[i]);
12             if(a[i]!=1) flag=0;
13             ans^=a[i];
14         }
15         if(flag)
16         {
17             if(n&1)
18                 printf("No\n");
19             else
20                 printf("Yes\n");
21         }
22         else
23         {
24             if(ans)
25                 printf("Yes\n");
26             else
27                 printf("No\n");
28         }
29     }
30     return 0;
31 }

时间: 2024-10-12 06:31:54

HDU 2509——anti-nim的相关文章

hdu 2509 Be the Winner

详解:hdu 1907 John - lihaogegehuting的专栏 - 博客频道 - CSDN.NET 两道题几乎一样 代码如下: #include<stdio.h> int main() { int T,a[100],i,sum,ok; while(~scanf("%d",&T)) { sum=0; ok=0; for(i=1;i<=T;i++) { scanf("%d",&a[i]); if(a[i]>1) ok=

HDU 2509 Nim博弈

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2509 题意:有N堆,谁最后拿谁输. 关键:判断孤单堆. 1 #include<cstdio> 2 #define ll long long 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 while( ~scanf("%d",&n)){ 9 int temp,ans=0,flag=0; 10 for(int i=

hdu 1907 John(anti nim)

John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 4704    Accepted Submission(s): 2720 Problem Description Little John is playing very funny game with his younger brother. There is one big bo

HDU 5011 Game Nim博弈 (涉及scanf和cin效率比较)

scanf是格式化输入,printf是格式化输出. cin是输入流,cout是输出流.效率稍低,但书写简便. 格式化输出效率比较高,但是写代码麻烦. 流输出操作效率稍低,但书写简便. cout之所以效率低,正如一楼所说,是先把要输出的东西存入缓冲区,再输出,导致效率降低. 缓冲区比较抽象,举个例子吧: 曾经就遇到过这样的情况(类似的), int i; cout<<'a'; cin>>i; cout<<'b'; 运行结果什么都没看到输出,输入一个整型比如3再按回车后ab同

Rabbit and Grass HDU - 1849 (Bash+Nim)

就是Bash 和 Nim 博弈的结合  可以直接 res ^= (Li + 1) % Mi 也可以 sg打个表  我打了个表 #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #in

hdu 2509 博弈 *

多堆的情况要处理好孤单堆 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 const int INF=0

HDU 2509 Be the Winner(取火柴博弈2)

传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int n; while(~scanf("%d",&n)) { int a,res=0; int c=0,g=0; for(int i=0;i<n;i++) { scanf("%d",&a); if(a>=2) c++;

HDU 4994 博弈。

F - 6 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4994 Description Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn,

Nim or not Nim?(hdu3032+SG函数)取走-分割游戏,经典

小k,终于忍不住了...正在笔记本上装win10,有点小激动. Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3032 Description Nim is a two-player mathematic game of strategy in which players take turns remov