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的位运算符—与(&)、非(~)、或(|)、异或(^)
		
位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...
 
随机推荐
- Android应用博客目录
			
应用有很多,开个博客都放进来方便查找,也方便修改 1 语言类: 1.1 JAVA 基础语言知识JAVA Collection与Collections,Array与Arrays的区别 JAVA练手--S ...
 - 资料汇总--Ajax中Put和Delete请求传递参数无效的解决方法(Restful风格)【转】
			
开发环境:Tomcat9.0 在使用Ajax实现Restful的时候,有时候会出现无法Put.Delete请求参数无法传递到程序中的尴尬情况,此时我们可以有两种解决方案:1.使用地址重写的方法传递参数 ...
 - JavaScript学习总结(三)——闭包、IIFE、原型、函数与对象
			
一.闭包(Closure) 1.1.闭包相关的问题 请在页面中放10个div,每个div中放入字母a-j,当点击每一个div时显示索引号,如第1个div显示0,第10个显示9:方法:找到所有的div, ...
 - 转载:sql用逗号连接多张表对应哪个join?
			
http://blog.csdn.net/huanghanqian/article/details/52847835 四种join的区别已老生常谈: INNER JOIN(也可简写为JOIN): 如果 ...
 - 关于shader的学习
			
教程地址:https://onevcat.com/2013/07/shader-tutorial-1 因为想做一些特效,所以想稍微了解一下shader的代码,一下是一些笔记 // Upgrade NO ...
 - POJ3278(KB1-C 简单搜索)
			
Catch That Cow Description Farmer John has been informed of the location of a fugitive cow and wants ...
 - sys模块 常用函数
			
sys模块是和python解释器打交道的 sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退出时exit(0),错误退出sys.exit(1) s ...
 - C Traps:运算
			
位移 如果sizeof(int) = 4,那么下面的代码的结果是什么? int x=255; printf("%d", x>>34); 实际输出:63 在编译这个代码时 ...
 - java集合(List集合与Map集合的数据转换)
			
List集合与Map集合的数据转换 实现List和Map数据的转换. 具体要求如下: 功能1:定义方法public void listToMap( ){ }将List中Student元素封装到Map中 ...
 - 浏览器根对象window之caches
			
在控制台输入window. caches可输出一个叫做CacheStorage的对象,它用来存储 Response 对象的.也就是说用来对 HTTP ,响应做缓存的.虽然 localStorage 也 ...