I - Matches Game

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

思路:两个相同的数异或后将会等于0,可以运用这个性质解决这题。(经典的博弈论问题)

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n;
int a[22];
while(scanf("%d",&n)!=EOF)
{
int out=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
out^=a[i];
}
if(out==0) printf("No\n"); //判断是否都成对
else printf("Yes\n");
}
return 0;
}

I - Matches Game(异或运算符的使用)的更多相关文章

  1. 136. Single Number【LeetCode】异或运算符,算法,java

    Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...

  2. 异或运算符(^)、与运算符(&)、或运算符(|)、反运算符(~)、右移运算符(>>)、无符号右移运算符(>>>)

    目录 异或(^).异或和 的性质及应用总结 异或的含义 异或的性质:满足交换律和结合律 异或的应用 按位 与运算符(&) 按位 或运算符(|) 取 反运算符(~) 右移运算符(>> ...

  3. c#的异或运算符

    int a = 5; int b = 30; Console.WriteLine(a^b); Console.ReadKey();  输出结果是27 这是因为 5的二进制是0000 010130的二进 ...

  4. javascript 异或运算符实现简单的密码加密功能

    写在前面的 当我们需要在数据库中存储用户的密码时,当然是不能明文存储的. 我们就是介绍一下用^运算符来实现简单的密码加密以及解密功能 上代码 首先,回顾一下基础知识. String.fromCharc ...

  5. Java的位运算符详解实例——与(&)、非(~)、或(|)、异或(^)

    位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...

  6. Java的位运算符—— 与(&)、非(~)、或(|)、异或(^)

    位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...

  7. Java的位运算符具体解释实例——与(&amp;)、非(~)、或(|)、异或(^)

    位运算符主要针对二进制,它包含了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.以下 ...

  8. 一分钟掌握位运算符—与(&)、非(~)、或(|)、异或(^)

    第一个版本:   位运算符的计算主要用在二进制中. 实际开发中也经常会遇到需要用到这些运算符的时候,同时这些运算符也被作为基础的面试笔试题. 所以了解这些运算符对程序员来说是十分必要的. 于此,记录下 ...

  9. Java的位运算符—与(&)、非(~)、或(|)、异或(^)

    位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...

随机推荐

  1. ubuntu系统

    Ubuntu 18.04 NVIDIA驱动安装总结:(需要和自己电脑上的显卡配套) https://blog.csdn.net/tjuyanming/article/details/80862290 ...

  2. 我用ASP.NET缓存之OutputCache

    [我的理解]页面缓存常用在网站上.Web应用系统上也用,但由于Web系统常与数据库打交道.时效性要求蛮强的,所以是否能用缓存得具体情况具体分析(很喜欢这句话“具体情况具体分析”,很符合国人的中庸之道) ...

  3. 【转】SQL语句统计每天、每月、每年的数据

    原文:https://www.cnblogs.com/Fooo/p/3435687.html SQL语句统计每天.每月.每年的数据 1.每年select year(ordertime) 年,sum(T ...

  4. win Apache服务消失或无法启动

    在bin目录中找到httpd.exe命令,如下图所示.启动cmd,即命令行,使用管理员身份运行,cd至该bin目录下.   使用cmd执行如下命令进行服务的安装:httpd.exe -k instal ...

  5. Jquery实现form表单提交后局部刷新页面的多种方法

    最近做一个小项目,刚好需要用到搜索功能,实现搜索框内输入数据然后按回车或者点击“提交”,然后给后台数据库处理并返回数据给前端,在前端局部更新数据. 但是遇到了一个小问题,就是form表单下任意输入框输 ...

  6. 【学习笔记】--- 老男孩学Python,day18 面向对象------ 属性,类方法,静态方法

    属性 属性: 将方法伪装成一个属性,代码上没有什么提升,只是更合理. 应用场景: 类中 要用名词时候可以用@property  比如,求面积,周长,平方,体脂 等运算时候 例如:   bmi是名词,最 ...

  7. AGC008E:Next or Nextnext

    传送门 考虑转化成图论问题,\(i\) 向 \(p_i\) 连边,那么合法方案一定是形成了若干个简单环或自环 考虑一个环内的情况: 如果 \(a_i=p_i\),那么 \(i\) 向 \(a_i\) ...

  8. Strut2开发经验总结

    1.如何在html静态页面中使用struts tomcat目录/conf/web.xml 文件中,找到 <servlet-mapping> <servlet-name>jsp& ...

  9. Pwn With longjmp

    前言 这个是 seccon-ctf-quals-2016 的一个题,利用方式还是挺特殊的记录一下. 题目链接 http://t.cn/RnfeHLv 正文 首先看看程序的安全措施 haclh@ubun ...

  10. node (1)

    一.介绍 Node.js是一个让JavaScript运行在服务器端的开发平台,它让JavaScript的触角伸到了服务器端. 但Node似乎有点不同: ● Node.js不是一种独立的语言,与PHP. ...