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
5 |
Sample Output
3 |
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 ...
随机推荐
- [CSS3] CSS Display Property: Block, Inline-Block, and Inline
Understanding the most common CSS display types of block, inline-block, and inline will allow you to ...
- [Hapi.js] Friendly error pages with extension events
hapi automatically responds with JSON for any error passed to a route's reply()method. But what if y ...
- iOS开发之让你的应用“动”起来
概览在 iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌.在这里你可以看到iOS中如何使用图层精简非交互 式绘图,如何通过核心动画创建基础动画.关键帧动 ...
- 已解决 C# 调用 MySQLDriverCS 类库 报 vshost32-clr2.exe 已停止工作
这几天修改一个项目是用C# 通过调用 MySQLDriverCS.dll 类库来操作 MySql数据库, 调试的会发生以上错误(直接运行是正常的),刚开始以为是兼容性问题,吧此错误百度上一粘贴有的人说 ...
- ajax参数中出现空格
jquery中发起ajax请求时的参数名中不能有空格.如果是get请求参数的中的空格会变成“+”符而在post请求中看不到这种变化,但无论哪种情况都无法与服务接口的参数就行匹配(此时进行调试也不会触发 ...
- PowerDesigner中在生成的数据库脚本中用name列替换comment列作为字段描述的方法
1 PowerDesigner中在生成的数据库脚本中用name列替换comment列作为字段描述的方法如下, 依次打开Tools -- Execute Commands -- Run Script,运 ...
- iOS指纹识别
#import "ViewController.h" #import <LocalAuthentication/LocalAuthentication.h> @inte ...
- VisualStudio2013快捷键
visual studio 2013 是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代码管控工具.集成开发环境(IDE)等等.VS 2013 中新增了很多提高 ...
- java开发webservice
第一部分:相关下载配置 1.开发环境 eclipse-jee-mars-2-win32-x86_64.zip http://www.eclipse.org/downloads/index-pac ...
- hdu1443(约瑟夫环游戏的原理 用链表过的)
Problem Description The Joseph's problem is notoriously known. For those who are not familiar with t ...