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. 24岁程序员, 一个人撑起App开发项目

    "疲惫吾心,怎样躲藏! 四处荒芜,怎话忧伤?"临近中秋,看到艾瑞斯的QQ签名,无尽的伤感.这个年仅24的青年.连续3年没有回家了,近期一个月总是失眠,没有家人的陪伴,就连女朋友都没 ...

  2. 安卓手机运行WINDOWS

    http://www.pcdiy.com.tw/detail/1974 我的ZenFone 2手机可以跑Windows啦! 就在台风来袭,有人正准备去泛舟的那天,国外的XDA论坛神人则是选择让自己的Z ...

  3. Android Studio com.android.dex.DexException: Multiple dex files define(重复引用包)

    如果你用Android Studio开发,并且要用其他项目作为library,这个问题是很容易出现的.出现这个问题的原因是包的重复引用,意思就是在你自己的项目中引用了某个包,而被你作为library的 ...

  4. JS实现拖拽小案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Spider_basic

    网络爬虫 定义:网络蜘蛛.网络机器人,抓取网络数据的程序 总结:用Python程序去模仿人去访问网站,模仿的越逼真越好 目的:通过有效的大量数据分析市场走势.公司决策 企业获取数据的方式 公司自有数据 ...

  6. PatentTips - Resource partitioning and direct access utilizing hardware support for virtualization

    BACKGROUND The present disclosure relates to the resource management of virtual machine(s) using har ...

  7. PHP路由技术的原理与实践

    0x00 路由实现原理 用户通过指定的URL范式对后台进行訪问.URL路由处理类进行处理后.转发到逻辑处理类,逻辑处理类将请求结果返回给用户. 约定URL范式和规则 约定一套自己喜欢的,对搜索引擎友好 ...

  8. git的安装及其使用

    在Windows上安装Git的快捷方式: 工具:1.Windows的console工具:ConEmu(https://conemu.github.io/)多窗口.记录log.多theme选择,操作Gi ...

  9. php实现运气模型(命运随机,克服困难)

    php实现运气模型(命运随机,克服困难) 一.总结 1.应该用表格来布局的,这种多列的用表格布局比div和span布局方便很多 2.span标签设置宽度:变成行内快元素:display:inline- ...

  10. orabbix 报错No suitable driver found for

     orabbix报错如下:   2018-07-11 14:35:20,119 [main] ERROR Orabbix - Error on Configurator for database qa ...