Matches Game
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12325 | Accepted: 7184 |
题目链接:http://poj.org/problem?id=2234
Description:
Here is a simple game. In this game, there are several piles of matches and two players. The two player play in turn. In each turn, one can choose a pile and take away arbitrary number of matches from the pile (Of course the number of matches, which is taken away, cannot be zero and cannot be larger than the number of matches in the chosen pile). If after a player’s turn, there is no match left, the player is the winner. Suppose that the two players are all very clear. Your job is to tell whether the player who plays first can win the game or not.
Input:
The input consists of several lines, and in each line there is a test case. At the beginning of a line, there is an integer M (1 <= M <=20), which is the number of piles. Then comes M positive integers, which are not larger than 10000000. These M integers represent the number of matches in each pile.
Output:
For each test case, output "Yes" in a single line, if the player who play first will win, otherwise output "No".
Sample Input:
2 45 45
3 3 6 9
Sample Output:
No
Yes
题意:
给出n堆石子,每一堆有相应的个数,然后问是否先手必胜。
题解:
Nim博弈模板题。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = ;
int n;
int a[N];
int main(){
while(scanf("%d",&n)!=EOF){
int x = ;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
x^=a[i];
}
int f = ;
for(int i=;i<=n;i++){
if((a[i]^x)<a[i]) f=;
}
if(f) cout<<"Yes"<< '\n';
else cout<<"No"<<'\n';
} return ;
}
POJ2234:Matches Game(Nim博弈)的更多相关文章
-
poj-2234 Matches Game Nim
Matches Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13264 Accepted: 7712 Des ...
-
POJ 2234 Matches Game(Nim博弈裸题)
Description Here is a simple game. In this game, there are several piles of matches and two players. ...
-
HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
-
HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
-
zoj3591 Nim(Nim博弈)
ZOJ 3591 Nim(Nim博弈) 题目意思是说有n堆石子,Alice只能从中选出连续的几堆来玩Nim博弈,现在问Alice想要获胜有多少种方法(即有多少种选择方式). 方法是这样的,由于Nim博 ...
-
hdu 1907 John&;&; hdu 2509 Be the Winner(基础nim博弈)
Problem Description Little John is playing very funny game with his younger brother. There is one bi ...
-
关于NIM博弈结论的证明
关于NIM博弈结论的证明 NIM博弈:有k(k>=1)堆数量不一定的物品(石子或豆粒…)两人轮流取,每次只能从一堆中取若干数量(小于等于这堆物品的数量)的物品,判定胜负的条件就是,最后一次取得人 ...
-
HDU - 1850 Nim博弈
思路:可以对任意一堆牌进行操作,根据Nim博弈定理--所有堆的数量异或值为0就是P态,否则为N态,那么直接对某堆牌操作能让所有牌异或值为0即可,首先求得所有牌堆的异或值,然后枚举每一堆,用已经得到的异 ...
-
博弈论中的Nim博弈
瞎扯 \(orzorz\) \(cdx\) 聚聚给我们讲了博弈论.我要没学上了,祝各位新年快乐.现在让我讲课我都不知道讲什么,我会的东西大家都会,太菜了太菜了. 马上就要回去上文化课了,今明还是收下尾 ...
随机推荐
-
配置NHibernate将枚举保存为Oracle数据库中的字符串
假设有这样一个枚举: /// <summary> /// 字典项类型 /// </summary> public enum DicItemType { [EnumDescrip ...
-
【Windows编程】系列第七篇:Menubar的创建和使用
上一篇我们学习了利用windows API创建工具栏和菜单栏,与上一篇紧密联系的就是菜单栏,菜单栏是一个大多数复杂一些的Windows应用程序不可或缺的部分.比如下图就是Windows自带的记事本的菜 ...
-
使用Connetion的属性RetainSameConnection
在SSIS的组件中,很多都会连接到数据库进行操作,Connection有一个属性RetainSameConnection,默认值是False,控制着连接的打开和关闭的时机. 1,如果Connectio ...
-
[PWA] Add web app to your Home Screen
Clone: Link Modify the structure: Move css, js, image, index.html to an 'app' folder. manifest.json: ...
-
HDU-1828-Picture(线段树)
Problem Description A number of rectangular posters, photographs and other pictures of the same shap ...
-
tyflow雨滴在物体上滑落测试
http://docs.tyflow.com/download/
-
Java提高班(四)面试必备—你不知道的数据集合
导读:Map竟然不属于Java集合框架的子集?队列也和List一样属于集合的三大子集之一?更有队列的正确使用姿势,一起来看吧! Java中的集合通常指的是Collection下的三个集合框架List. ...
-
IOS 小新兵
2017-07-02 lipo -info BaiduOAuthSDK.a 查看a文件支持的架构 第一个坎: 报错: 未找到模块baiduLogin对应的类BaiduLoginModule.若是自 ...
-
Mybatis的类型处理器
Mybatis在预处理语句(PreparedStatement)中设置一个参数时,会用默认的typeHandler进行处理. 这句话是什么意思呢,当你想用姓名查询一个人的信息时 <select ...
-
[sql]join的5种方式:inner join、left(outer) join、right (outer) Join、full(outer) join、cross join
现在有两张表 如下图所示: 一 .inner join 返回的结果:两个表的交集行 二. left join 是left outer join的简写 返回结果:左表的 ...