HDU 3537 Daizhenyang's Coin(博弈,翻硬币)
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
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.
1
0
4
0 1 2 3
No
Yes
经典模型。
详见: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(博弈,翻硬币)的更多相关文章
- hdu 3537 Daizhenyang's Coin (翻硬币游戏)
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; ]; i ...
- HDU 3537 Daizhenyang's Coin 翻硬币博弈
题意: 给你n个硬币,你可以从中拿出来1.2.3个硬币,它们不一定要连续,你只需要保证拿出来的硬币中那个下标最大的硬币一定要是正面朝上,最后谁不能操作,谁就输了 题解: 翻硬币游戏 结论: 局面的SG ...
- hdu 3537 Daizhenyang's Coin(博弈-翻硬币游戏)
题意:每次可以翻动一个.二个或三个硬币.(Mock Turtles游戏) 初始编号从0开始. 当N==1时,硬币为:正,先手必胜,所以sg[0]=1. 当N==2时,硬币为:反正,先手必赢,先手操作后 ...
- HDU 3537 Daizhenyang's Coin
链接 [http://acm.hdu.edu.cn/showproblem.php?pid=3537] 题意 题意:已知一排硬币中有n个硬币正面朝上,输入正面朝上的硬币的位置ai.两人轮流操作, 每次 ...
- hdu 3537 Daizhenyang's Coin 博弈论
详见:http://www.cnblogs.com/xin-hua/p/3255985.html 约束条件6 代码如下: #include<iostream> #include<st ...
- HDU 3537 (博弈 翻硬币) Daizhenyang's Coin
可以参考Thomas S. Ferguson的<Game Theory>,网上的博客大多也是根据这个翻译过来的,第五章讲了很多关于翻硬币的博弈. 这种博弈属于Mock Turtles,它的 ...
- hdu 3537(博弈,翻硬币)
题意:给定了每个正面朝上的硬币的位置,然后每次可以翻1,2,3枚硬币,并且最右边的硬币开始必须是正面朝上的. 分析: 约束条件6:每次可以翻动一个.二个或三个硬币.(Mock Turtles游戏) 初 ...
- 【hdu 3537】Daizhenyang's Coin
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...
- HDU 3537 基础翻硬币模型 Mock Turtles 向NIM转化
翻硬币游戏,任意选3个,最右边的一个必须是正面.不能操作者败. 基本模型..不太可能自己推 还是老实记下来吧..对于单个硬币的SG值为2x或2x+1,当该硬币的位置x,其二进制1的个数为偶数时,sg= ...
随机推荐
- 【Android framework】am命令启动Activity流程
源码基于Android 4.4. am start -W -n com.dfp.test/.TEstActivity -W:等目标Activity启动后才返回 -n:用于设置Intent的Comp ...
- C#反射动态调用dll中的方法及使用QuartZ.net实现作业调度
using Quartz; using Quartz.Impl; using System; using System.Collections.Generic; using System.Linq; ...
- [New learn]GCD的基本使用
https://github.com/xufeng79x/GCDDemo 1.简介 介绍GCD的使用,介绍多种队列与同步异步多种情况下的组合运行情况. 2.基本使用步骤 如果使用GCD则一般也就两个步 ...
- ajax之深入解析(2)
我们前面实现了用原生的JavaScript代码实现ajax的异步数据传输.接下来,我们再使用一个流行的js框架jQuery来实现ajax. 通过 jQuery AJAX 方法,我们能够使用 HTTP ...
- 应用程序有bug崩溃重启的案例2
------解决思路----------------------另外做一个服务或者程序定时监控系统进程.程序奔溃的话,都会在入口函数出现异常处理一下winform可以有两个事件来捕获主线程异常和线程异 ...
- (转载)IntelliJ IDEA 自动导入包 快捷方式
原文地址:IntelliJ IDEA 自动导入包 快捷方式 idea可以自动优化导入包,但是有多个同名的类调用不同的包,必须自己手动Alt+Enter设置 设置idea导入包 勾选标注 1 选项,In ...
- php之trait-实现多继承
PHP是单继承的语言,在PHP 5.4 Traits出现之前,PHP的类无法同时从两个基类继承属性或方法.php的Traits和Go语言的组合功能类似,通过在类中使用use关键字声明要组合的Trait ...
- Message Queue中的推与拉(转)
Message Queue的设计和实现(7)http://mp.weixin.qq.com/s/zQdDBAHu1UgJJzxH2eCHgQ 数据发送中的推与拉. 当MQ要把数据给消费者的时候,就涉及 ...
- 探索sklearn | 鸢尾花数据集
1 鸢尾花数据集背景 鸢尾花数据集是原则20世纪30年代的经典数据集.它是用统计进行分类的鼻祖. sklearn包不仅囊括很多机器学习的算法,也自带了许多经典的数据集,鸢尾花数据集就是其中之一. 导入 ...
- Ext 目录
adapter:负责将里面提供第三方底层库(包括Ext自带的底层库)映射为Ext所支持的底层库. build: 压缩后的ext全部源码(里面分类存放). docs: API帮助文档. exmaples ...