hdu2095 像水题的不错题 异或运算
异或运算的基础有点忘记了
先介绍一下。。2个数异或 就是对于每一个二进制位进行位运算
具有2个特殊的性质
1、一个数异或本身恒等于0,如5^5恒等于0;
2、一个数异或0恒等于本身,如5^0恒等于5。
3 满足交换律
find your present (2) |
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, and you can assume that only one number appear odd times.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<1000000, and n is odd) at first. Following that, n positive integers will be given in a line, all integers will smaller than 2^31. 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
|
Sample Output
|
and you can assume that only one number appear odd times.注意这句话。。。只有ans会出现odd次
根据这几个性质知
1、一个数异或本身恒等于0,如5^5恒等于0;
2、一个数异或0恒等于本身,如5^0恒等于5。
3 满足交换律
8^2^2^8^3^3^8^8^5=5; 用来寻找一串数字中唯一odd次出现的数
所以显然用异或运算是很完美的解法
代码就不贴了
hdu2095 像水题的不错题 异或运算的更多相关文章
- poj 1002:487-3279(水题,提高题 / hash)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 236746 Accepted: 41288 Descr ...
- Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~
->点击<- A. Summer Camp time limit per test 1 second memory limit per test 256 megabytes input s ...
- BZOJ 3097: Hash Killer I【构造题,思维题】
3097: Hash Killer I Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 963 Solved: 36 ...
- PHP实现类似题库抽题效果
PHP实现类似题库抽题效果 大家好,我顾某人又回来了,最近学了一点PHP,然后就想写个简单小例子试试,于是就写了一个类似于从题库抽题的东西,大概就是先输入需要抽题的数量,然后从数据库中随机抽取题目. ...
- PAT乙级真题及训练题 1025. 反转链表 (25)
PAT乙级真题及训练题 1025. 反转链表 (25) 感觉几个世纪没打代码了,真是坏习惯,调了两小时把反转链表调出来了,心情舒畅. 这道题的步骤 数据输入,数组纪录下一结点及储存值 创建链表并储存上 ...
- 啤酒和饮料|2014年蓝桥杯B组题解析第一题-fishers
啤酒和饮料|2014年第五届蓝桥杯B组题解析第一题-fishers 啤酒和饮料 啤酒每罐2.3元,饮料每罐1.9元.小明买了若干啤酒和饮料,一共花了82.3元. 我们还知道他买的啤酒比饮料的数量少,请 ...
- 『Python题库 - 填空题』151道Python笔试填空题
『Python题库 - 填空题』Python笔试填空题 part 1. Python语言概述和Python开发环境配置 part 2. Python语言基本语法元素(变量,基本数据类型, 基础运算) ...
- 洛谷 P4148 简单题 KD-Tree 模板题
Code: //洛谷 P4148 简单题 KD-Tree 模板题 #include <cstdio> #include <algorithm> #include <cst ...
- 纪中10日T1 2300. 【noip普及组第一题】模板题
2300. [noip普及组第一题]模板题 (File IO): input:template.in output:template.out 时间限制: 1000 ms 空间限制: 262144 K ...
随机推荐
- POJ 1469 ZOJ1140 二分匹配裸题
很裸,左点阵n,右点阵m 问最大匹配是否为n #include <cstdio> #include <cstring> #include <vector> usin ...
- C#基于委托的带参数的消息传递设计
需求场景 在对象A中注册消息,指定回调函数 在对象B中解释消息,调用对应的回调函数,附上对应的参数对象 定义 public delegate void MessengerDelegate(object ...
- SQLserver 连接+开窗函数+视图+事务
今天学习SQLserver 连接以及开窗函数..加油! 1.复习:查询(检索)->筛选列->筛选行:distinct top where 运算符与关键字:比较运算符,逻辑运算符,betwe ...
- js静态方法
1.ajax() 方法是属于“函数”本身的,和返回的对象没有关系 2.bark药调用,必须药new Hashiqi()得到对象,且由返回对象才能调用 3.ajax()方法药调用,不需要new对象,直接 ...
- mysql 数据库连接池
hibernate配置C3P0详解 分类: hibernate 2013-08-14 16:16 1213人阅读 评论 ...
- Python3.5入门学习记录-模块
模块让你能够有逻辑地组织你的Python代码段. 把相关的代码分配到一个 模块里能让你的代码更好用,更易懂. 模块也是Python对象,具有随机的名字属性用来绑定或引用. 简单地说,模块就是一个保存了 ...
- Qss样式(二)
Qss 其实就是一段文本,当然得按一定格式来写.下面请看Qss的语法格式: 选择器 { 属性1:值:属性2:值:--属性n:值:} 对应上篇文章的Qss样式: 现在我们可以来解释这段话的意思了: 对应 ...
- Python学习(七) 流程控制if语句
在Python中流程控制if语句采用如下格式: if expression : statement elif expression : statement elif expression : stat ...
- 本部校赛 蛇形填数(二)problen1338
Description 萌萌哒cy学姐参加去年的新生杯的时候,蛇形矩阵那题被她分分钟秒掉,于是她决定出一个更难的题目,她要求矩阵里的每个数都是质数,当然,蛇形的规则也略有变化 如2*3矩阵: 2 7 ...
- 跪求 EF缓存问题 也不知道是不是缓存 问题
1.数据库里面查的结果 2 vs里面查的结果 为什么 不是16 而是2 下面是代码 /// <summary> /// 权限检查 /// </summary> public ...