Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 677 Accepted Submission(s): 321

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

0

1

0

4

0 1 2 3

Sample Output

Yes

No

Yes

【题目链接】:http://acm.hdu.edu.cn/showproblem.php?pid=3537

【题解】



首先要明白一些事情,不然没法做;

有这样的结论:局面的SG 值为局面中每个正面朝上的棋子单一

存在时的SG 值的异或和。即一个有k个硬币朝上,朝上硬币位置

分布在的翻硬币游戏中,SG值是等于k个独立的开始时只有一个硬

币朝上的翻硬币游戏的SG值异或和。比如THHTTH这个游戏中,2号、

3号、6号位是朝上的,它等价于TH、TTH、TTTTTH三个游戏和,

即sg[THHTTH]=sg[TH]^sg[TTH]^sg[TTTTTH].

我们的重点就可以放在单个硬币朝上时的SG值的求法。

所以现在只考虑单个硬币朝上的(最后一个硬币正面朝上,其他都是反面朝上);

下面为方便起见用0代表反面朝上,1代表正面朝上

N=0
先手输->sg[0]=0;
N=1
只有一个硬币的时候
即
1
则先手赢;
sg[1]=1;
N=2
即
01
这里
01可以通过一次操作变成{00,10}
对于00其对应N=0的sg,即sg[0]=0;
对于10其对应N=1的sg,即sg[1]=1;
(不要忘了上面整个游戏可以分解成若干个小游戏的思想);
则sg[2]=mex(sg[0],sg[1]);(mex是不包括集合里面的数的最小整数);
sg[2]=2;
N=3
即
001
这里001可以通过一次操作变成{000,010,100,110}
000对应N=0,sg[0]=0;
010对应N=2,sg[2]=2;
100对应N=1,sg[1]=1;
110分解为N=1和N=2的情况,sg=sg[1]^sg[2]=3;
所以
sg[3]=mex{sg[0],sg[2],sg[1],3}=4
N=4
即
0001
0001可以通过一次操作变成{0000,0010,0100,1000,0110,1010,1100}
①0000->sg[0]=0
②0010->sg[3]=4
③0100->sg[2]=2
④1000->sg[1]=1
⑤0110->sg=sg[2]^sg[3]=6
⑥1010->sg=sg[1]^sg[3]=5
⑦1100->sg=sg[1]^sg[2]=3
所以sg[4] = mex{0,4,2,1,6,5,3}=7

到了这里我们可以依据这个规则写出打表程序(在题解下方)

得到如下数据

sg[0]=0

sg[1]=1

sg[2]=2

sg[3]=4

sg[4]=7

sg[5]=8

sg[6]=11

sg[7]=13

sg[8]=14

sg[9]=16

sg[10]=19

sg[11]=21

sg[12]=22

sg[13]=25

sg[14]=26

sg[15]=28

sg[16]=31

sg[17]=32

sg[18]=35

sg[19]=37

sg[20]=38

可以看到N=x的时候

sg[x]要么等于2*(x-1)+1要么等于2*(x-1)

直接给出结论了

当x-1的二进制形式里面有奇数个1的时候,sg[x]=2*(x-1);

有偶数个1的时候sg[x]=2*(x-1)+1;

且sg[0]=0;

但是这里题目给的下标是从0开始的;

所以上面得到的sg下标要移位一下

sg[0]=1

sg[1]=2

sg[2]=4

sg[3]=7 ->下标为3代表的是N=4的情况;

…

这样就更方便了:

直接看所给的下标x的二进制形式里面有多少个1;

为奇数则sg[x]=2*x;否则sg[x]=2*x+1

最后看看所有的sg函数的异或值是多少;

为0则先手败,否则先手赢;

注意在这个题目里,先手败是输出Yes!

**不要忘了硬币的位置可能重复,最毒XX心:(

【打表程序】↓↓↓

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int sg[200];
bool flag[200];
string s;
int now; int main()
{
freopen("F:\\rush.txt","r",stdin);
freopen("F:\\rush_out.txt","w",stdout);
sg[0] = 0;sg[1] = 1;
s = "01";
now = 2;
while (now <= 50)
{
memset(flag,false,sizeof flag);
string ts = s;
int len = ts.length();
ts[len-1] = '0';
flag[0] = true;
rep1(i,0,len-2)
{
ts[i]='1';
flag[sg[i+1]] = true;
ts[i]='0';
}
rep1(i,0,len-3)
{
ts[i]='1';
rep1(j,i+1,len-2)
{
ts[j]='1';
flag[sg[i+1]^sg[j+1]] = true;
ts[j]='0';
}
ts[i]='0';
}
rep1(j,0,200)
if (!flag[j])
{
sg[now] = j;
break;
}
s='0'+s;
now++;
}
rep1(i,0,20)
printf("sg[%d]=%d\n",i,sg[i]);
fclose(stdin);
fclose(stdout);
return 0;
}

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int n;
map <LL,bool> dic; bool judge(LL x)
{
int cnt = 0;
while (x > 0)
{
if (x&1)
cnt++;
x>>=1;
}
return cnt&1;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
while (~scanf("%d",&n))
{
dic.clear();
LL ans = 0;
rep1(i,1,n)
{
LL x;
rel(x);
if (dic[x]) continue;
dic[x] = true;
if (judge(x))
ans = ans ^ (2*x);
else
ans = ans^(2*x+1);
}
if (ans==0)
puts("Yes");
else
puts("No");
}
return 0;
}

【hdu 3537】Daizhenyang's Coin的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 3951】Coin Game

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

  8. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  9. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

随机推荐

  1. C语言速度优化之指针赋值与if推断

    近期在写的一个项目须要优化处理速度,我写了一下程序来測试指针赋值与指针推断的速度比較.结果让我大吃一惊. #include <stdio.h> #include <stdlib.h& ...

  2. JAVA异常机制简述

    1.类的继承结构 在JAVA所有的异常对象都是Throwable类的一个子类的实例 Exception包含两个分支,由于程序错误导致的异常属于RuntimeException,比如数组下标越界,空指针 ...

  3. matlab 可视化 —— 高级 api(montage)、insertObjectAnnotation、insertMaker

    1. montage:同时显示多个图像 thumbnails = train_x(:, :, :, 1:100); thumbnails = imresize(thumbnails, [64, 64] ...

  4. js面向对象1----了解构造函数

    一.构造函数与实例的区别 1 构造函数  构造函数主要是一种用于生成对象的饼干模具,这些对象具有默认属性和属性方法,它可以创建多个共享特定特性和行为的对象.  构造函数只是一个函数,但当函数遇到了ne ...

  5. 洛谷——P3128 [USACO15DEC]最大流Max Flow

    https://www.luogu.org/problem/show?pid=3128 题目描述 Farmer John has installed a new system of  pipes to ...

  6. ThreadLocal深入理解与内存泄露分析

    ThreadLocal 当使用ThreadLocal维护变量时,ThreadLocal为每个使用该变量的线程提供独立的变量副本.所以每个线程都能够独立地改变自己的副本.而不会影响其他线程所相应的副本. ...

  7. centos php 安装memcached 扩展 支持sasl

    1.安装sasl yum install cyrus-sasl-lib.x86_64 yum install cyrus-sasl-devel.x86_64 2.下载libmemcached wget ...

  8. python 命令行:help(),'more'不是内部或外部命令,也不是可运行的程序或批处理文件

    Python下使用help(dict),显示'more'不是内部或外部命令,也不是可运行的程序或批处理文件,该如何处理? 环境变量设置的问题,进入 Path 的环境变量设置界面,将;%SystemRo ...

  9. Android android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1

    Android中数据库处理使用cursor时,游标不是放在为0的下标,而是放在为-1的下标处开始的. 也就是说返回给cursor查询结果时,不能够马上从cursor中提取值. 下面的代码会返回错误 U ...

  10. [Angular] Change component default template (ng-content, ng-template, ngTemplateOutlet, TemplateRef)

    Here is the defulat tab header template: <ng-template #defaultTabHeader let-tabs="tabsX" ...