I - Matches Game

Description


  1. 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 players 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


  1. 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


  1. For each test case, output "Yes" in a single line, if the player who play first will win, otherwise output "No".

Sample Input

  1. 2 45 45
  2. 3 3 6 9

Sample Output


  1. No
  2. Yes

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

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int n;
  8. int a[22];
  9. while(scanf("%d",&n)!=EOF)
  10. {
  11. int out=0;
  12. for(int i=1;i<=n;i++)
  13. {
  14. scanf("%d",&a[i]);
  15. out^=a[i];
  16. }
  17. if(out==0) printf("No\n"); //判断是否都成对
  18. else printf("Yes\n");
  19. }
  20. return 0;
  21. }

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. [转]iCheck表单美化插件使用方法详解(含参数、事件等)

    本文转自:http://www.exp99.com/jswz/f2e/1408696007_34.html iCheck   特色: 1.在不同浏览器(包括ie6+)和设备上都有相同的表现 — 包括 ...

  2. C#绑定数据

    1.<asp:DropDownList <asp:DropDownList ID="ddlclientType" runat="server" Wi ...

  3. VMWare安装Mac OS X

    原文作者 谷月K 2016.08.16 18:55 字数3473 随着iPhone.iPad.Mac等苹果产品越来越火爆,越来越多的初学者想要了解和尝试苹果平台,包括苹果操作系统Mac OS X.苹果 ...

  4. Vue 基本指令和html常用标签结合使用综合案例(含代码)

    最近项目中要开发一个OA审批:里边涉及到流程跳转(流程较多),具体方案有:直接下一步,选择参与人或者选择某一个流程之后再选择参与人: 我们前端是APiCloud开发,这里我主要使用Vue来实现,把实现 ...

  5. Leet Palindrome Partitioning II

    class Solution { public: int minCut(string s) { int len = s.length(); ]; char* s_dp = new char[len * ...

  6. 移动端Web Meta标签

    原文  http://blog.segmentfault.com/jianjian_532633/1190000000654839 添加到推刊   在介绍移动端特有 meta 标签之前,先简单说一下 ...

  7. Code Signal_练习题_shapeArea

    A 1-interesting polygon is just a square with a side of length 1. An n-interesting polygon is obtain ...

  8. iphone设置fiddler代理测试

    iPhone上配置fiddler为代理方法: 打开IPhone, 找到你的网络连接,打开HTTP代理,输入Fiddler所在机器的IP地址(比如:192.168.1.104) 以及Fiddler的端口 ...

  9. ubuntu下使用g++编译时默认支持C++11 配置方法

    1.只需要在源文件程序中加上如下一行代码: #pragma GCC diagnostic error "-std=c++11" 此时源文件代码如下: #pragma GCC dia ...

  10. 一步一步pwn路由器之radare2使用全解

    前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 radare2 最近越来越流行,已经进入 github 前 25了 ...