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 ...
随机推荐
- bash的元字符(下)
` "Esc"键正下方键,替换命令 PS1=`command` {} 在当前shell中运行命令 {command1;command2} | 创建命令间的管道 command1 | ...
- 关于asp:login控件和验证码的问题?(转)
1.验证码页面添加.2.将这验证码页面添加到login控件中:拖曳一Login控件,将之切换到模式下,在Html源文件中在表格中密码那行后添加: <tr> <td style= ...
- webservice 远程调试配置
在.NET 中已经默认将WEBSERVICE的远程调试功能关闭,有的时候我们需要远程调试程序的时候,就需要打开此功能我们只需在WEBSERVICE的项目的中添web.config的<system ...
- Django中ModelForm应用
Django中ModelForm的应用 在传统中Form提交的POST的数据在服务器端获取时将不得不一一获取并验证数据的可靠性,但是使用django提供的Form时可简化该过程并提供相应的验证,同时D ...
- Glide的加载图片的帮助类,用来把图片圆角或者改成圆形图片
Glide虽然非常好用但是没找到把图片圆角的方法,所以百度了一个非常不错的加载类自己实现圆角图 感谢原文章作者:http://blog.csdn.net/weidongjian/article/det ...
- setNeedsDisplay、layoutSubViews
UIView的setNeedsDisplay和setNeedsLayout方法.首先两个方法都是异步执行的.而setNeedsDisplay会调 用自动调用drawRect方法,这样可以拿到UIGra ...
- poj1458 求最长公共子序列 经典DP
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 45763 Accepted: 18 ...
- Python学习笔记2(控制语句)
1.if条件语句 if(表达式): 语句1 else: 语句2 2.if...elif...else判断语句 if(表达式1):语句1 elif(表达式2):语句2 ... elif(表达式n):语句 ...
- Qt 'void QWidget::show()' is inaccessible
今天在编写Qt窗体头文件时,尽然碰到了这样的报错,'void QWidget::show()' is inaccessible,'QWidget' is not an accessible base ...
- Vim复制文件全部内容到系统剪贴板
参考:http://vim.wikia.com/wiki/%22copy_all_to_clipboard%22_howto vim中有两个buffer为系统的剪贴板,它们为: * (primary ...