Daizhenyang's Coin

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

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
 
Source
 
Recommend
zhouzeyong
 

经典模型。

详见:http://www.cnblogs.com/kuangbin/p/3218060.html

各个位置的SG值异或就行了

注意先去掉重合的点

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std; int SG(int x)
{
int tmp = x;
int cnt = ;
while(tmp)
{
if(tmp&)cnt++;
tmp>>=;
}
if(cnt&)return *x;
else return *x + ;
} int a[]; int main()
{
int n;
while(scanf("%d",&n)==)
{
for(int i = ;i < n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
n = unique(a,a+n)-a;
int sum = ;
for(int i = ;i < n;i++)
sum ^= SG(a[i]);
if(sum)printf("No\n");
else printf("Yes\n");
}
return ;
}

HDU 3537 Daizhenyang's Coin(博弈,翻硬币)的更多相关文章

  1. hdu 3537 Daizhenyang's Coin (翻硬币游戏)

    #include<stdio.h> #include<algorithm> #include<string.h> using namespace std; ]; i ...

  2. HDU 3537 Daizhenyang's Coin 翻硬币博弈

    题意: 给你n个硬币,你可以从中拿出来1.2.3个硬币,它们不一定要连续,你只需要保证拿出来的硬币中那个下标最大的硬币一定要是正面朝上,最后谁不能操作,谁就输了 题解: 翻硬币游戏 结论: 局面的SG ...

  3. hdu 3537 Daizhenyang's Coin(博弈-翻硬币游戏)

    题意:每次可以翻动一个.二个或三个硬币.(Mock Turtles游戏) 初始编号从0开始. 当N==1时,硬币为:正,先手必胜,所以sg[0]=1. 当N==2时,硬币为:反正,先手必赢,先手操作后 ...

  4. HDU 3537 Daizhenyang's Coin

    链接 [http://acm.hdu.edu.cn/showproblem.php?pid=3537] 题意 题意:已知一排硬币中有n个硬币正面朝上,输入正面朝上的硬币的位置ai.两人轮流操作, 每次 ...

  5. hdu 3537 Daizhenyang's Coin 博弈论

    详见:http://www.cnblogs.com/xin-hua/p/3255985.html 约束条件6 代码如下: #include<iostream> #include<st ...

  6. HDU 3537 (博弈 翻硬币) Daizhenyang's Coin

    可以参考Thomas S. Ferguson的<Game Theory>,网上的博客大多也是根据这个翻译过来的,第五章讲了很多关于翻硬币的博弈. 这种博弈属于Mock Turtles,它的 ...

  7. hdu 3537(博弈,翻硬币)

    题意:给定了每个正面朝上的硬币的位置,然后每次可以翻1,2,3枚硬币,并且最右边的硬币开始必须是正面朝上的. 分析: 约束条件6:每次可以翻动一个.二个或三个硬币.(Mock Turtles游戏) 初 ...

  8. 【hdu 3537】Daizhenyang's Coin

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

  9. HDU 3537 基础翻硬币模型 Mock Turtles 向NIM转化

    翻硬币游戏,任意选3个,最右边的一个必须是正面.不能操作者败. 基本模型..不太可能自己推 还是老实记下来吧..对于单个硬币的SG值为2x或2x+1,当该硬币的位置x,其二进制1的个数为偶数时,sg= ...

随机推荐

  1. 安全测试===sqlmap(叁)转载

    十五.操作系统控制 1.执行任意操作系统命令 参数:--os-cmd和--os-shell 若数据库管理系统是MySQL.PostgreSQL或微软的SQL Server且当前用户有相关权限Sqlma ...

  2. 使用 ftrace 调试 Linux 内核【转】

    转自:http://blog.csdn.net/adaptiver/article/details/7930646 使用 ftrace 调试 Linux 内核,第 1 部分 http://blog.c ...

  3. 64_g3

    gimp-resynthesizer-2.0-6.20160601git787ee5a.fc2..> 11-Feb-2017 05:36 77650 gimp-save-for-web-0.29 ...

  4. mac10.9下安装Android

    这里记录一下mac下安装android比较快捷的方法 首先,到这里下载Android SDK,这个是集成的,所有工具一应俱全,免去了下载一堆东西的烦恼.具体包括如下: Eclipse + ADT pl ...

  5. C中级 MariaDB Connector/C API 编程教程

    引言 - 环境搭建 首先开始环境搭建. 主要在Window 10 + Visual Studio 2015 上构建使用 mariadb connector/c api 进行数据操作开发. 为什么选择在 ...

  6. ArcGIS Server配置端口

    写在前面,GIS服务器必须连通到外网,基于某些情况,可能一个机组有多态服务器,担任不同的角色,有Web服务器.数据库服务器和GIS服务器等,但是可能购买时只有一个外网IP,这样是不行的.JS脚本运行在 ...

  7. 看懂sh脚本

    1 开头 程序必须以下面的行开始(必须方在文件的第一行): #!/bin/sh 符号#!用来告诉系统它后面的参数是用来执行该文件的程序.在这个例子中我们使用/bin/sh来执行程序. 当编写脚本完成时 ...

  8. 使用PuTTY连接树莓派

    这是 meelo 原创的 玩转树莓派 系列文章 PuTTY是一个支持Telnet.SSH协议,实现远程登录的软件.树莓派的官方操作系统Raspbian默认开启了SSH协议进行登录,这样即使没有专门的显 ...

  9. nodejs pm2使用

    参考地址:http://www.jianshu.com/p/43525232b03b 参考地址:http://blog.csdn.net/leo_perfect/article/details/536 ...

  10. 京东前端:PhantomJS 和NodeJS在网站前端监控平台的最佳实践

    1. 为什么需要一个前端监控系统 通常在一个大型的 Web 项目中有很多监控系统,比如后端的服务 API 监控,接口存活.调用.延迟等监控,这些一般都用来监控后台接口数据层面的信息.而且对于大型网站系 ...