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 ;
}
												

最新文章

  1. Apworks框架实战(四):使用Visual Studio开发面向经典分层架构的应用程序:从EasyMemo案例开始
  2. 开发错误记录3:问题 Error:failed to find Build Tools revision 23.0.2
  3. p1304 家族
  4. C++混合编程之idlcpp教程Python篇(2)
  5. HDU4417 - Super Mario(主席树)
  6. SKPhysicsContact类
  7. Sql server Lock
  8. IOS 特定于设备的开发:使用加速器启动屏幕上的对象
  9. Spring IOC 之个性化定制the nature of a bean
  10. Java 8 新特性1-函数式接口
  11. ThinkPHP中处理验证码的问题
  12. Android之PendingIntent的深入理解
  13. Android系统定制和源码开发以及源码编译(附视频)
  14. Chrome浏览器如何不让它缓存?
  15. 如何取消一个目录的git初始化
  16. 炸弹人 之 N A B C D
  17. Tomcat优化详细教程
  18. 智慧监狱来了!SaCa EMM 助推现代监狱建设迈上新台阶
  19. ios学习--结合UIImageView实现图片的移动和缩放
  20. spark包

热门文章

  1. node模块之path——path.join和path.resolve的区别
  2. Centos7.3安装和配置jre1.8转
  3. python中Flask模块的使用
  4. iOS 时间校准解决方案
  5. 【转】vue+axios 前端实现登录拦截(路由拦截、http拦截)
  6. [LeetCode] 43. Multiply Strings ☆☆☆(字符串相乘)
  7. ActiveMQ broker 集群, 静态发现和动态发现
  8. 0.5px的宽度的边框
  9. 【Java算法】求质数的算法
  10. linux用户管理 用户和用户组管理