HDU2509 Be the Winner

Be the Winner

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3062    Accepted Submission(s): 1709

Problem 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

Source

ECJTU 2008 Autumn Contest

Recommend

lcy

反尼姆博弈(anti-nim)

该类问题的判定方法:

  下面是从知乎找到的分析↓

奇异局势,所有堆的xor和==0.

假定S是非奇异局势,T是奇异局势。
一堆中石子数量>=2,表示充裕堆, =1表示孤单堆。

S0即非奇异局势下,充裕堆为0的状态
S1即非奇异局势下,充裕堆为1的状态
S2即非奇异局势下,充裕堆>=2的状态

T0即奇异局势下,充裕堆为0的状态
T2即奇异局势下,充裕堆>=2的状态

1.奇异局势的定义可知,S能转移到T,能转移到S, T只能转移到S

2.S0必败,T0必胜

3.S1必胜,因为S1只需要转移到S0即可。

4.S2必胜,T2必败。
1)T2只能转移到S1 和 S2
2)若T2转移到S1 则T2败,若T2转移到S2,S2只需要转回到T2即可。所以S2胜,T2败。

所以:
必胜态:T0,S1,S2
必败态:S0,T2

作者:公丕鑫
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

另外还有一篇比较详细的证明分析:http://qianmacao.blog.163.com/blog/static/20339718020123555821140/

然后是代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 int main(){
 8     int n;
 9     while(scanf("%d",&n)!=EOF){
10         int i,j;
11         int s=0;bool flag=0;
12         for(i=1;i<=n;i++){
13             scanf("%d",&j);
14             s^=j;
15             if(j>1)flag=1;
16         }
17         if(!flag){//充裕堆为0
18             if(n%2)//堆数为奇数,必败
19                 printf("No\n");
20             else printf("Yes\n");
21         }
22         else{//充裕堆>0
23             if(s==0)//奇异局势
24                 printf("No\n");
25             else
26                 printf("Yes\n");
27         }
28     }
29     return 0;
30 }
时间: 2024-10-26 16:57:49

HDU2509 Be the Winner的相关文章

hdu2509

1 //Accepted 0MS 232K 2 #include <cstdio> 3 #include <cstring> 4 int ans; 5 int t; 6 int n; 7 void slove() 8 { 9 int x; 10 ans=0; 11 t=0; 12 for (int i=0;i<n;i++) 13 { 14 scanf("%d",&x); 15 ans=ans^x; 16 if (x>1) t++; 17 }

CodeForces-2015 HIAST Collegiate Programming Contest-Gym-100952A-Who is the winner?

A. Who is the winner? time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output A big marathon is held on Al-Maza Road, Damascus. Runners came from all over the world to run all the way along the road

HDU 5754 Life Winner Bo 组合博弈

Life Winner Bo Problem Description Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G. The size of the chessboard is N×M.The top left corner is numbered(1,1) and the lower right corner is numberd (N,M). For each game,B

Diabetic Retinopathy Winner&#39;s Interview: 1st place, Ben Graham

Diabetic Retinopathy Winner's Interview: 1st place, Ben Graham Ben Graham finished at the top of the leaderboard in the high-profileDiabetic Retinopathy competition. In this blog, he shares his approach on a high-level with key takeaways. Ben finishe

Facebook IV Winner&#39;s Interview: 1st place, Peter Best (aka fakeplastictrees)

Facebook IV Winner's Interview: 1st place, Peter Best (aka fakeplastictrees) Peter Best (aka fakeplastictrees) took 1st place in Human or Robot?, our fourth Facebook recruiting competition. Finishing ahead of 984 other data scientists, Peter ignored

5754Life Winner Bo

给定一个n*m的矩阵,有四种棋子(国际象棋的王,王后,骑士,车).起点在(1,1)先走到(n,m)获胜. 分析:车是nim博弈.王后是威佐夫博弈.王和骑士写两个1000*1000的预处理即可. hdu5754Life Winner Bo 题目连接 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 co

CodeForces 2A Winner

Winner Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 2A Description The winner of the card game popular in Berland "Berlogging" is determined according to the following rules.

Liberty Mutual Property Inspection, Winner&#39;s Interview: Qingchen Wang

Liberty Mutual Property Inspection, Winner's Interview: Qingchen Wang The hugely popular Liberty Mutual Group: Property Inspection Prediction competition wrapped up on August 28, 2015 with Qingchen Wang at the top of a crowded leaderboard. A total of

How Much Did It Rain? Winner&#39;s Interview: 1st place, Devin Anzelmo

How Much Did It Rain? Winner's Interview: 1st place, Devin Anzelmo An early insight into the importance of splitting the data on the number of radar scans in each row helped Devin Anzelmo take first place in the How Much Did It Rain? competition. In