I - Matches Game(异或运算符的使用)
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(异或运算符的使用)的更多相关文章
- 136. Single Number【LeetCode】异或运算符,算法,java
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- 异或运算符(^)、与运算符(&)、或运算符(|)、反运算符(~)、右移运算符(>>)、无符号右移运算符(>>>)
目录 异或(^).异或和 的性质及应用总结 异或的含义 异或的性质:满足交换律和结合律 异或的应用 按位 与运算符(&) 按位 或运算符(|) 取 反运算符(~) 右移运算符(>> ...
- c#的异或运算符
int a = 5; int b = 30; Console.WriteLine(a^b); Console.ReadKey(); 输出结果是27 这是因为 5的二进制是0000 010130的二进 ...
- javascript 异或运算符实现简单的密码加密功能
写在前面的 当我们需要在数据库中存储用户的密码时,当然是不能明文存储的. 我们就是介绍一下用^运算符来实现简单的密码加密以及解密功能 上代码 首先,回顾一下基础知识. String.fromCharc ...
- Java的位运算符详解实例——与(&)、非(~)、或(|)、异或(^)
位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...
- Java的位运算符—— 与(&)、非(~)、或(|)、异或(^)
位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...
- Java的位运算符具体解释实例——与(&)、非(~)、或(|)、异或(^)
位运算符主要针对二进制,它包含了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.以下 ...
- 一分钟掌握位运算符—与(&)、非(~)、或(|)、异或(^)
第一个版本: 位运算符的计算主要用在二进制中. 实际开发中也经常会遇到需要用到这些运算符的时候,同时这些运算符也被作为基础的面试笔试题. 所以了解这些运算符对程序员来说是十分必要的. 于此,记录下 ...
- Java的位运算符—与(&)、非(~)、或(|)、异或(^)
位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...
随机推荐
- C#语法之扩展
扩展方法使你能够向现有类型“添加”方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型. 扩展方法是一种特殊的静态方法,但可以像扩展类型上的实例方法一样进行调用.这是msdn的描述.上面几句 ...
- C#,一些非常简单但应该知道的知识点
1.本地变量 一看这个标题你可能会一愣,这是个什么东东.看个小例子: static void main(){ int a=10; MyClass mc=new MyClass();} 呵呵,这 ...
- java并发编程的艺术(一)---锁的基本属性
本文来源于翁舒航的博客,点击即可跳转原文观看!!!(被转载或者拷贝走的内容可能缺失图片.视频等原文的内容) 若网站将链接屏蔽,可直接拷贝原文链接到地址栏跳转观看,原文链接:https://www.cn ...
- 地址解析协议ARP,网络层协议IP、ICMP协议
分析所用软件下载:Wireshark-win32-1.10.2.exe 阅读导览 1. 分析并且应用ARP协议 2.分析IP协议 3.分析ICMP协议 1.分析arp报文的格式与内容 (1)ping ...
- Intellij IDEA run coverage之覆盖率测试
Intellij IDEA run coverage之覆盖率测试 idea 的coverage + 我们自己写的测试用例.最后看一下,我们要测的代码有没有测试到,这是一个不错的提高代码质量的方法. i ...
- win8.1 pro-64位下安装配置MinGW—64位
1.下载MinGW-w64位:http://mingw-w64.org/doku.php 点击Downloads 说明:这边使用的是在线安装方式: 在网站里可以看到他安装后的文件夹: 2.安装 运行m ...
- java泛型详解(加一点语法糖)
首先请看如下代码: public class Test{ public static void main(String str[]) { Hashtable h =new Hashtable(); h ...
- Ubuntu14.04安装Torch7笔记
Ubuntu14.04安装Torch7笔记 利用快捷键Ctrl+Alt+T打开Ubuntu终端 第一步: 获取安装LuauJIT(C语言编写的Lua的解释器)和Torch所必需的依赖包. 代码如下: ...
- Spring Boot—06集成前端模板thymeleaf
Spring Boot建议使用这些模板引擎,避免使用JSP,若一定要使用JSP将无法实现Spring Boot的多种特性 pom.xml <dependency> <groupId& ...
- Tab Key not working when using Xfce remote desktop
Xfce 远程桌面Tab键设置 Use CTRL-tab instead of tab The XFCE Terminal has kidnapped the tab key for a featu ...