HDU 3537 Daizhenyang's Coin 翻硬币博弈

来源:互联网 发布:win10仿mac桌面dock 编辑:程序博客网 时间:2024/05/16 03:14
点击打开链接

Daizhenyang's Coin

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 281    Accepted Submission(s): 129


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.
 

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枚硬币朝上,其中最右面的那枚硬币在翻转前必须朝上的,其中可以翻转一枚、两枚或者三枚硬币,问初始态是必胜态还是必败态。
点击打开链接
sg打表:
#include<stdio.h>#include<string.h>int vis[1007],sg[1007];int main(){    for(int i=1;i<100;i++)    {        memset(vis,0,sizeof(vis));        vis[0]=1;//翻一枚        for(int j=0;j<i;j++)            vis[sg[j]]=1;//翻两枚        for(int j=0;j<i;j++)            for(int k=0;k<j;k++)                vis[sg[j]^sg[k]]=1;//翻三枚        for(int k=0;;k++)            if(!vis[k]){sg[i]=k;break;}        printf("%d\n",sg[i]);    }}

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int vis[107],s[107];int solve(int x){    int count=0,t=x;    while(x)    {        if(x&1)count++;        x>>=1;    }    if(count%2)return 2*t;    else return 2*t+1;}int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        if(n==0){printf("Yes\n");continue;}        memset(vis,0,sizeof(vis));        int ans=0,len=0;        for(int i=0;i<n;i++)            scanf("%d",&vis[i]);        sort(vis,vis+n);        s[0]=vis[0];        for(int i=1;i<n;i++)            if(vis[i]!=s[len])                s[++len]=vis[i];        for(int i=0;i<=len;i++)            ans^=solve(s[i]);        if(!ans)printf("Yes\n");        else printf("No\n");    }    return 0;}



1 0