HDU 3537 Daizhenyang's Coin(博弈-sg)
来源:互联网 发布:淘宝采集软件哪个好 编辑:程序博客网 时间:2024/05/15 23:48
Daizhenyang's Coin
Problem Description
We know that Daizhenyang is chasing a girlfriend. As we all know, whenever you chase a beautiful girl, there'll always be an opponent, or a rival. In order to take one step ahead in this chasing process, Daizhenyang decided to prove to the girl that he's better and more intelligent than any other chaser. So he arranged a simple game: Coin Flip Game. He invited the girl to be the judge.
In this game, n coins are set in a row, where n is smaller than 10^8. They took turns to flip coins, to flip one coin from head-up to tail-up or the other way around. Each turn, one can choose 1, 2 or 3 coins to flip, but the rightmost selected must be head-up before flipping operation. If one cannot make such a flip, he lost.
As we all know, Daizhenyang is a very smart guy (He's famous for his 26 problems and Graph Theory Unified Theory-Network Flow does it all ). So he will always choose the optimal strategy to win the game. And it's a very very bad news for all the competitors.
But the girl did not want to see that happen so easily, because she's not sure about her feelings towards him. So she wants to make Daizhenyang lose this game. She knows Daizhenyang will be the first to play the game. Your task is to help her determine whether her arrangement is a losable situation for Daizhenyang.
For simplicity, you are only told the position of head-up coins. And due to the girl's complicated emotions, the same coin may be described twice or more times. The other coins are tail-up, of course.
Coins are numbered from left to right, beginning with 0.
In this game, n coins are set in a row, where n is smaller than 10^8. They took turns to flip coins, to flip one coin from head-up to tail-up or the other way around. Each turn, one can choose 1, 2 or 3 coins to flip, but the rightmost selected must be head-up before flipping operation. If one cannot make such a flip, he lost.
As we all know, Daizhenyang is a very smart guy (He's famous for his 26 problems and Graph Theory Unified Theory-Network Flow does it all ). So he will always choose the optimal strategy to win the game. And it's a very very bad news for all the competitors.
But the girl did not want to see that happen so easily, because she's not sure about her feelings towards him. So she wants to make Daizhenyang lose this game. She knows Daizhenyang will be the first to play the game. Your task is to help her determine whether her arrangement is a losable situation for Daizhenyang.
For simplicity, you are only told the position of head-up coins. And due to the girl's complicated emotions, the same coin may be described twice or more times. The other coins are tail-up, of course.
Coins are numbered from left to right, beginning with 0.
Input
Multiple test cases, for each test case, the first line contains only one integer n (0<=n<=100), representing the number of head-up coins. The second line has n integers a1, a2 … an (0<=ak<10^8) indicating the An-th coin is head up.
Output
Output a line for each test case, if it's a losable situation for Daizhenyang can, print "Yes", otherwise output "No" instead.
Sample Input
01040 1 2 3
Sample Output
YesNoYes
Source
2010 ACM-ICPC Multi-University Training Contest(11)——Host by BUPT
题目大意:
解题思路:有一排硬币,告诉 你n个正面朝上的硬币的位置,你可以选择任意位置的1~3个硬币翻转一下,但是问你先手是否会输。
解题代码:通过求sg发现规律
sg 1 2 4 7 8 11 13 14
x 0 1 2 3 4 5 6 7
找到规律,sg[x],如果x的二进制1的个数为奇数,sg[x]=2*x ,否则 sg[x]=2*x+1;
然后把各个Sg的值异或最终就是答案
#include <iostream>#include <cstdio>#include <set>using namespace std;int sg(int x){ int ans=0,tmp=x; while( x>0 ){ if( (x&1) ) ans++; x/=2; } if( (ans&1) ) return 2*tmp; else return 2*tmp+1;}int main(){ int n,x; while(scanf("%d",&n)!=EOF){ int ans=0,x; set <int> mys; for(int i=0;i<n;i++){ scanf("%d",&x); mys.insert(x); } for(set <int>::iterator it=mys.begin();it!=mys.end();it++){ ans^=sg(*it); } if(ans==0) printf("Yes\n"); else printf("No\n"); } return 0;}
3 0
- HDU 3537 Daizhenyang's Coin(博弈-sg)
- hdu 3537 Daizhenyang's Coin(博弈-翻硬币游戏)
- HDU3537-Daizhenyang's Coin(博弈SG-打表)
- hdu 3537 Daizhenyang's Coin 博弈(Nim游戏+sg定理+找规律)
- HDU 3537 Daizhenyang's Coin (经典翻硬币博弈问题)
- HDU 3537 Daizhenyang's Coin 翻硬币博弈
- HDU 3537 Daizhenyang's Coin
- 【hdu 3537】Daizhenyang's Coin
- HDU 3537 Daizhenyang's Coin (博弈论、翻硬币游戏)
- HDOJ 3537 Daizhenyang's Coin
- HDU 3537 Daizhenyang's Coin (Mock Turtles 游戏)
- HDOJ 3537 Daizhenyang's Coin (翻硬币游戏)
- hdu3537 Daizhenyang's Coin
- HDU 1536(sg博弈) S-Nim
- HDU 1536 S-Nim(SG博弈)
- hdu3537 Daizhenyang's Coin 翻硬币,(Mock Turtles游戏)
- hdu 1536、hdu 1944 S-Nim(博弈SG函数)
- HDU 1536 & POJ 2960 S-Nim(博弈 SG)
- LeetCode _interleaving string
- 儿童性侵案-2
- 隐马尔可夫模型攻略
- uva:10670 - Work Reduction(贪心)
- CDLINUX U盘安装教程
- HDU 3537 Daizhenyang's Coin(博弈-sg)
- 函数重载
- 配置WebSite的IIS时遇到的问题与解决方法
- eclipse 新建 java 文件时自动生成注释
- Humble Numbers
- C#在WinCE平台上的相关技巧
- 儿童性侵案-3
- System.Data.SqlClient.SqlException: Login failed for user
- cookie