Problem Description
In the new year party, everybody will get a “special present”.Now it’s your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present has a card number on it, and your present’s card number will be the one that different from all the others.For example, there are 5 present, and their card numbers are 1, 2, 3, 2, 1.so your present will be the one with the card number of 3, because 3 is the number that different from all the others.

Input
The input file will consist of several cases.
Each case will be presented by an integer n (1<=n<=200, and n is odd) at first. Following that, n positive integers will be given in a line. These numbers indicate the card numbers of the presents.n = 0 ends the input.

Output
For each case, output an integer in a line, which is the card number of your present.

Sample Input
5
1 1 3 2 2
3
1 2 1
0

Sample Output
3
2

题意:找出一行数中独立的数!

按位异或的3个特点:
(1) 0^0=0,0^1=1 0异或任何数=任何数
(2) 1^0=1,1^1=0 1异或任何数-任何数取反
(3) 任何数异或自己=把自己置0

先说一下异或运算的运算法则:
1. a ^ b = b ^ a
2. a ^ b ^ c = a ^ (b ^ c) = (a ^ b) ^ c
3. d = a ^ b ^ c 可以推出 a = d ^ b ^ c
4. a ^ b ^ a = b

对于性质1,显而易见。
对于性质2和4,就是可以查找出一组数列中具有奇数个数的数。比如:
题目:有2n+1个数,其中有n个数出现过两次,只有一个数字出现过一次。要求是找出这个数字。

import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);while(sc.hasNext()){int n =sc.nextInt();if(n==0){return ;}int m =0;int s;while(n-->0){s = sc.nextInt();m = m^s;}System.out.println(m);}}
}

转载于:https://www.cnblogs.com/webmen/p/5739288.html

HDOJ(HDU) 1563 Find your present!(异或)相关推荐

  1. HDOJ HDU 2080 夹角有多大II ACM 2080 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=2080 ...

  2. HDOJ HDU 1106 排序 ACM 1106 IN HDU

    //MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 :             http://acm.hdu.edu.cn/showproblem.php?pi ...

  3. HDOJ HDU 2058 The sum problem ACM 2058 IN HDU

    //MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 :          http://acm.hdu.edu.cn/showproblem.php?pid=2 ...

  4. HDOJ HDU 1709 The Balance ACM 1709 IN HDU

    //MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址 :          http://acm.hdu.edu.cn/showproblem.php?pid=1 ...

  5. HDU 2095 find your present (2)

    原以为这是一纯水题,就果断开了1000000了数组给它(1300多K),没想Memory果断超了,后来又用链表做(写了2000多K),再次无情的被Memory刷了,无耐百度一下,竟然发现别人的代码才3 ...

  6. HDOJ HDU 1849 Rabbit and Grass ACM 1849 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=1849 ...

  7. HDOJ HDU 2088 Box of Bricks ACM 2088 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址:          http://acm.hdu.edu.cn/showproblem.php?pid=2088 ...

  8. HDOJ HDU 1129 Do the Untwist

    HDOJ 1129 Do the Untwist 题目 点此查看 HDOJ 1129 Do the Untwist 分类 模拟 题意 模拟解密 字幕数字对照 "_" = 0, &q ...

  9. hdu 3949(线性基模版) 异或和中第k小的数

    传送门 给定 n(n \le 10000)n(n≤10000) 个数 a_1, a_2, \ldots, a_na​1​​,a​2​​,-,a​n​​,以及 Q(Q\le 10000)Q(Q≤1000 ...

  10. HDOJ(HDU) 2500 做一个正气的杭电人(水~)

    Problem Description 做人要有一身正气,杭电学子都应该如此.比如我们今天的考试就应该做到"诚信"为上. 每次考试的第一个题目总是很简单,今天也不例外,本题是要求输 ...

最新文章

  1. HOGDescriptor 描述类
  2. Android 实现简单的插件化模块化
  3. 在MATLAB中,用Simulink搭建一个二阶传递函数模型
  4. java 转时区_java – 时区转换
  5. java中3des cbc,js與java通用的3DES(ECB,CBC)+Base64加密編碼,解碼解密
  6. Effective C# Item30:尽可能实现CLS兼容的程序集
  7. 一文读懂clickhouse的世界
  8. 的采样方式_DR803M4水质自动采样器(岸边站自动排空型)
  9. Java String trim()方法示例
  10. 台式计算机读取不了移动硬盘,电脑识别不了硬盘的原因
  11. matlab机器人画圆轨迹规划
  12. 台式电脑桌面没有计算机图标,电脑桌面上“我的电脑”的图标没了怎么办
  13. Word、Excel组合批量打印信封(转)
  14. excel自动调整列宽_高效使用Excel透视表,必须要注意的十个细节
  15. linux开机故障,Entering emeryency mode. Exit the shell to continue.
  16. 第一章 计算机基础知识
  17. Linux 往事:一个不会像 GNU 那样大而专业的 OS 是如何成为主流的?
  18. RAII (Resource Acquirement Is Initialization)
  19. 用DIV+CSS技术设计的西安旅游网站18页(web前端网页制作课作业)HTML+CSS旅游网站设计与实现
  20. Chrome游戏《Boxel Rebound》可自制赛道的弹跳小方块

热门文章

  1. 天津西站,大屏幕程序出错啦
  2. 解决办法:无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系
  3. 对SP光刻机表示谨慎
  4. C# dataGridView控件 控件中至少有一列没有模板问题【解决】 添加新列
  5. android自定义view案例,Android自定义View,你摸的透透的了?
  6. java线性表多个属性_顺序存储结构的线性表(java实现)
  7. python类的继承举例_python类的继承实例详解
  8. 485通讯线是几芯的_RS232/485串口通讯基础知识
  9. Hibernate 缓存机制详细分析
  10. ORACLE检索数据一致性与事务恢复