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 Nim博弈裸题,所有堆的值异或得0则先手输,否则先手赢。 Nim博弈及异或理解可看百度百科 这游戏看上去有点复杂,先从简单情况开始研究吧。如果轮到你的时候,只剩下一堆石子,那么此时的必胜策略肯定是把这堆石子全部拿完一颗也不给对手剩,然后对手就输了。
如果剩下两堆不相等的石子,必胜策略是通过取多的一堆的石子将两堆石子变得相等,以后如果对手在某一堆里拿若干颗,你就可以在另一堆中拿同样多的颗数,直至胜利。
如果你面对的是两堆相等的石子,那么此时你是没有任何必胜策略的,反而对手可以遵循上面的策略保证必胜。如果是三堆石子…… 如果a、b两个值不相同,则异或结果为1。如果a、b两个值相同,异或结果为0。
 #include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std; int main()
{
int n;
long long tmp,res;
while(~scanf("%d",&n))
{
scanf("%lld",&res);
for(int i=;i<n;i++)
{
scanf("%lld",&tmp);
res ^=tmp;
}
if(res==)
printf("No\n");
else
printf("Yes\n");
}
return ;
}
												

POJ 2234 Matches Game(Nim博弈裸题)的更多相关文章

  1. POJ 3624 Charm Bracelet(01背包裸题)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38909   Accepted: 16862 ...

  2. POJ 2234 Matches Game (尼姆博弈)

    题目链接: https://cn.vjudge.net/problem/POJ-2234 题目描述: Here is a simple game. In this game, there are se ...

  3. POJ 2234 Matches Game 尼姆博弈

    题目大意:尼姆博弈,判断是否先手必胜. 题目思路: 尼姆博弈:有n堆各a[]个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,多者不限,最后取光者得胜. 获胜规则:ans=(a[1]^a[ ...

  4. POJ 2234 Matches Game(取火柴博弈1)

    传送门 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  5. POJ 2234 Matches Game

    Matches Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7567   Accepted: 4327 Desc ...

  6. 题解——POJ 2234 Matches Game

    这道题也是一个博弈论 根据一个性质 对于\( Nim \)游戏,即双方可以任取石子的游戏,\( SG(x) = x \) 所以直接读入后异或起来输出就好了 代码 #include <cstdio ...

  7. HDU 1846 Brave Game【巴什博弈裸题】

    Brave Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  8. poj 3264 Balanced Lineup(RMQ裸题)

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 43168   Accepted: 20276 ...

  9. POJ 3667 线段树区间合并裸题

    题意:给一个n和m,表示n个房间,m次操作,操作类型有2种,一种把求连续未租出的房间数有d个的最小的最左边的房间号,另一个操作时把从x到x+d-1的房间号收回. 建立线段树,值为1表示未租出,0为租出 ...

随机推荐

  1. ubuntu Sublime Text 2编辑器安装

    官网下载http://www.sublimetext.com/2 选择合适的包下载回来的格式是.tar.bz2格式,需要进行解压. 1,解压:tar -xvf Sublime\ Text\ 2.0.2 ...

  2. oracle having sum group by 详解

    Aggregate functions (like SUM) often need an added GROUP BY functionality. 集合函数(类似SUM)经常需要用GROUP BY来 ...

  3. Mybatis自动生成实体类,映射文件,dao

    http://www.mybatis.org/generator/index.html 方法一:eclipse插件式 1.下载 mybatis-generator-core-1.3.2.jar 解压后 ...

  4. 使用spring-cloud-starter-bus-amqp做微服务配置刷广播,config-client配置 未刷新的 问题

    在需要配置刷新的(类或方法)上 加上 @RefreshScope 扩展:spring cloud:config-server中@RefreshScope的"陷阱"

  5. Day2----Jmeter 压测

    一.jmeter 压测1.一般压测时间为10-15分钟就行,设置时间在调度器配置--持续时间中设置,例如:想压10分钟,则持续时间输入:600 1.线程数:发送请求的用户数,即并发数 2.Ram-up ...

  6. daal4py 随机森林模型训练mnist并保存模型给C++ daal predict使用

    # daal4py Decision Forest Classification Training example Serialization import daal4py as d4p import ...

  7. weblogic修改安装路径教程

    我们有一个安装好的weblogic,我们想再装一个weblogic或者想把weblogic装到别的目录去,最直接的做法是从头装一个. 但是从头装一个是比较费时费力的,尤其是打补丁环节和创domain环 ...

  8. SpringBoot与docker

    1.简介 Docker是一个开源的应用容器引擎: Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其它使用者开源直接使用这个镜像: 运行中的这个镜像称为容器,容器启 ...

  9. 关于JAVA的一些知识点

    1.java.lang.Runtime.getRuntime().availableProcessors() Returns the number of processors available to ...

  10. chrome google mozilla firefox bookmarks import export

    chrome导出导入bookmarks 1◆ google帐号 自己申请,脑补   2◆ google访问 脑补   suggestion   Lantern   3◆ 步骤 4◆ 导入 sample ...