Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9297   Accepted: 5365

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

Source

POJ Monthly,readchild

THINKING

  Nim游戏的经典模型。
  随机博弈指的是这样的一个博弈游戏,目前有任意堆石子,每堆石子个数也是任意的,双方轮流从中取出石子,规则如下:1)每一步应取走至少一枚石子;每一步只能从某一堆中取走部分或全部石子;2)如果谁取到最后一枚石子就胜。也就是尼姆博弈(Nimm Game)必败局面:也叫奇异局势无论做出何出操作,最终结果都是输的局面。必败局面经过2次操作后,可以达到另一个必败局面。必胜局面:经过1次操作后可以达到必败局面。即当前局面不是必败局面就是必胜局面,而必胜局面可以一步转变成必败局面。
  最终状态:
  (1)最后剩下一堆石子;(必胜局面)
  (2)剩下两堆,每堆一个;(必败局面)
  (3)当石子剩下两堆,其中一堆只剩下1颗,另一堆剩下多于n颗石子时,当前取的人只需将多于1颗的那一堆取出n-1颗,则局面变为刚才提到的必败局面。(必胜局面)判断当前局势是否为必胜(必败)局势:
    1)把所有堆的石子数目用二进制数表示出来,当全部这些数按位异或结果为0时当前局面为必败局面,否则为必胜局面;
    2)在必胜局面下,因为所有数按位异或的结果
是大于零的,那么通过一次取,将这个(大于其它所有数按位异或的结果的)数下降到其它所有数按位异或的结果,这时局面就变为必败局面了。定理:一组自然数中必然存在一个数,它大于等于其它所有数按位异或的结果。证明:原命题等价于,设a1^a2^... ^an=p,p≠0时,必存在k,使得ak^p<ak< span="">(当p=0时,对于任意的k,有ak^p=ak)。
    设p的最高位是第q位,则至少存在一个k,使得ak的第q位也是1,而ak^p的第q位为0,所以ak^p<ak
      补缀一点,(a^b)^b=a^(b^b)=a^0=a,所以ak^p相当于“其它所有数按位异或的结果”。
  参考:https://sites.google.com/site/lene13/Home/sophi-mass/0-7
  例1:2 45 4545^45=0,45和45的异或等于0。
  例 2:3 3 6 9局势(3,6,9)因为3^6^9不等于0,所以这是一个必胜局势。 
  3 011^6 110 5 101 即从第3堆中的9个中取走9-5=4个,则(3,6,9)->(3,6,5),3^6^5=0,故(3,6,5)为奇异局势,即从必胜局势转变成必败局势。
 
解释来源:http://blog.chinaunix.net/uid-20776510-id-1846450.html

CODE

  PASCAL记得不要用EOF,要用seekeof才好。
var x,y,n:int64;i:longint;
procedure main;
begin
y:=;
read(n);
for i:= to n do
begin
read(x);
y:=y xor x;
end;
if y= then writeln('No')
else writeln('Yes');
end;
begin
while not seekeof do
main;
end.

[POJ2234]Matches Game的更多相关文章

  1. POJ-2234 Matches Game---尼姆博奕裸题

    题目链接: https://vjudge.net/problem/POJ-2234 题目大意: 尼姆博奕裸题 思路: 直接异或 #include<iostream> #include< ...

  2. poj-2234 Matches Game Nim

    Matches Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13264   Accepted: 7712 Des ...

  3. POJ2234 Matches Game 尼姆博弈 博弈论

    http://poj.org/problem?id=2234 尼姆博弈(Nimm's Game) 指的是这样一个博弈游戏:有任意堆物品,每堆物品的个数是任意的,双方轮流从中取物品,每一次只能从一堆物品 ...

  4. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  5. 【Mark】博弈类题目小结(HDU,POJ,ZOJ)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...

  6. POJ 博弈论

    poj1704 Georgia and Bob 题目链接:http://poj.org/problem?id=1704 题意:如图所示,两个人在玩一个游戏,排成直线的格子上有n个棋子,两人依次将棋子向 ...

  7. POJ2234:Matches Game(Nim博弈)

    Matches Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12325   Accepted: 7184 题目链 ...

  8. 【poj2234】 Matches Game

    http://poj.org/problem?id=2234 (题目链接) 题意 经典取火柴游戏 Solution 裸的Nim游戏,也就是取石子. 整个游戏的sg值为每一堆火柴(子游戏)的异或和. 代 ...

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

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

随机推荐

  1. this在JavaScript中的工作范围

    this在JavaScript中的工作范围 在一个函数中,this的行为,取决于JavaScript函数的调用方式和定义方式,而不仅仅是看它如何被定义的. var fullname = 'Fu';va ...

  2. dedecms 获取文章发布时间和获取文章最后更新时间

    文章发布时间:[field:senddate function=MyDate('m-d',@me)/] 文章最后更新时间:[field:pubdate function=MyDate('m-d',@m ...

  3. opengl多重采样

    效果图如下,两幅图效果是一样的,只是换了个背景.两幅图均是左侧使用了多重采样,右侧的没有使用多重采样.

  4. 七,WPF的元素绑定

    数据绑定是一种关系,该关系告诉WPF从一个源对象提取一些信息,并使用这些信息设置目标对象的属性,目标属性总是依赖项属性,然而,源对象可以是任何内容. 源对象是WPF元素并且源属性是依赖项属性的数据绑定 ...

  5. UNICODE编码表

    UNICODE简介 Unicode(统一码.万国码.单一码)是一种在计算机上使用的字符编码.Unicode 是为了解决传统的字符编码方案的局限而产生的,它为每种语言中的每个字符设定了统一并且唯一的二进 ...

  6. C#中如何按字节数截取字符串?

    http://www.cnblogs.com/xuejie/archive/2012/12/14/2818452.html

  7. cocos2d lua的cclog 在logcat中显示

    -- cclog cclog = function(...) release_print(string.format(...)) end 改成这样就可以了

  8. iOS多线程常用类说明--备用参考

    iOS的多线程,涉及到如下一些类,这里集中做个介绍,免得混淆. 1.NSTimer 很显然,这是定时器类 2.NSTask iOS 不支持 NSTask 在很多并发操作的时候,多线程太耗资源,也太危险 ...

  9. Centos安装gnome主菜单编辑器无

    首选项---主菜单--   即是alacarte.. centos ===安装  alacarte.noarch 0:0.12.4-1.el6 即可.

  10. spring framework 各版本源码下载地址

    现在spring的源码下载地址真是不好找,这次终于找到了.记录一下,以帮助需要的朋友. https://github.com/spring-projects/spring-framework/tags ...