HDU2509 Be the Winner
Be the Winner
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3062 Accepted Submission(s): 1709
For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last is
the loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win).
2 2
1
3
Yes
太长不看版:
计算所有堆的异或和。若异或和不为0,那么一定有取法将其转化为0;若异或和为0,因为必须取,那么不得不将其转化成异或和不为0的状态。
最后面对着都取完的状态(0)的人输,按以上规律判定能不能占先机将异或和转化为0即可。
长也要看版:
反尼姆博弈(anti-nim)
该类问题的判定方法:
下面是从知乎找到的分析↓
奇异局势,所有堆的xor和==0.
假定S是非奇异局势,T是奇异局势。
一堆中石子数量>=2,表示充裕堆, =1表示孤单堆。
S0即非奇异局势下,充裕堆为0的状态
S1即非奇异局势下,充裕堆为1的状态
S2即非奇异局势下,充裕堆>=2的状态
T0即奇异局势下,充裕堆为0的状态
T2即奇异局势下,充裕堆>=2的状态
1.奇异局势的定义可知,S能转移到T,能转移到S, T只能转移到S
2.S0必败,T0必胜
3.S1必胜,因为S1只需要转移到S0即可。
4.S2必胜,T2必败。
1)T2只能转移到S1 和 S2
2)若T2转移到S1 则T2败,若T2转移到S2,S2只需要转回到T2即可。所以S2胜,T2败。
所以:
必胜态:T0,S1,S2
必败态:S0,T2
作者:公丕鑫
来源:知乎
另外还有一篇比较详细的证明分析:http://qianmacao.blog.163.com/blog/static/20339718020123555821140/
然后是代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
int i,j;
int s=;bool flag=;
for(i=;i<=n;i++){
scanf("%d",&j);
s^=j;
if(j>)flag=;
}
if(!flag){//充裕堆为0
if(n%)//堆数为奇数,必败
printf("No\n");
else printf("Yes\n");
}
else{//充裕堆>0
if(s==)//奇异局势
printf("No\n");
else
printf("Yes\n");
}
}
return ;
}
HDU2509 Be the Winner的更多相关文章
- HDU-2509 Be the Winner
http://acm.hdu.edu.cn/showproblem.php?pid=2509 Be the Winner Time Limit: 2000/1000 MS (Java/Others) ...
- hdu2509 Be the Winner 博弈
Let's consider m apples divided into n groups. Each group contains no more than 100 apples, arranged ...
- anti-nim 游戏
游戏描述: 桌上有n堆石子,游戏双方轮流取石子,每次只能从一堆中取出任意数目的石子,不能不取,取走最后一个石子者失败. 结论: 先手必胜,当且仅当: ①.所有堆的石子数都为1,且游戏的SG值为0. ② ...
- HDU 5754 Life Winner Bo 组合博弈
Life Winner Bo Problem Description Bo is a "Life Winner".He likes playing chessboard gam ...
- HDU 2509 Be the Winner nim博弈变形
Be the Winner Problem Description Let's consider m apples divided into n groups. Each group contai ...
- HDU5754 Life Winner Bo(博弈)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life Winner" ...
- Codeforces Beta Round #2 A. Winner
A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...
- Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang
Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang Recruit Ponpare is Japan's leading ...
- winner tree 胜者树
在树形选择排序中,利用锦标赛思想建立的树称为胜者树. 1.每个非终端节点存储的是左右孩子节点中的优胜者. 2.通过减少比较次数,提高效率. 3.胜者树就是一颗特殊的线段树. 一.构建树 Procedu ...
随机推荐
- 查询OOP课程
--检测有没有名称为MySchool的数据库 use master if exists (select * from sysdatabases where name='myschool') begin ...
- Java连接Elasticsearch集群
package cn.test; import java.net.InetAddress; import java.net.UnknownHostException; import org.elast ...
- performSelector:withObject:afterDelay: 精要概览(持续更新)
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay; - ...
- [win]AD域组策略wifi自动配置
http://wenku.baidu.com/link?url=MC950wliAZNeVUJ2M6Y1VTi5faqo7kG374fyBjW57r0qyLJkBZLg5ypiql4RFywQ8q7y ...
- 通过HttpClient来调用Web Api接口~续~实体参数的传递
并且我们知道了Post,Put方法只能有一个FromBody参数,再有多个参数时,上讲提到,需要将它封装成一个对象进行传递,而这讲主要围绕这个话题来说,接口层添加一个新类User_Info,用来进行数 ...
- 用 eric6 与 PyQt5 实现python的极速GUI编程(系列03)---- Drawing(绘图)(1)-- 绘写文字
[概览] 本文实现如下的程序:(在窗体中绘画出文字) 主要步骤如下: 1.在eric6中新建项目,新建窗体 2.(自动打开)进入PyQt5 Desinger,编辑图形界面,保存 3.回到eric 6, ...
- Android开发探秘之四:利用Intent实现数据传递
在Android开发过程中,很多人都熟悉Intent,这是个用于在多个View之间共享数据的类.本节主要是继承上节,通过点选ListView中的文本,把文本中的URL加载到一个新的页面上,并且打印出来 ...
- 安卓界面篇(一) 自定义一个topbar
步骤一: 先在values 里 新建一个attrs.xml 来设置我们的属性值: <?xml version="1.0" encoding="utf-8" ...
- 路由器 NorFlash与NandFlash区别
在淘宝上买修改openwrt的路由器,基本上都是改的16MB flash,那么为什么不改到1GB呢? 现在U盘的价格也很便宜啊. 于是我调查了一下,发现flash分为两种,NorFlash与NandF ...
- Android响应式界面开发要点
现在很多项目需要到达同一个Apk既可以在Phone上跑也尅在tablet上跑,即界面要适应不同尺寸和类型的需要而自动调整.这个即为响应式设计.在web开发商响应式设计已经是个常谈的内容了,而对于and ...