异或运算的基础有点忘记了

先介绍一下。。2个数异或 就是对于每一个二进制位进行位运算

具有2个特殊的性质

1、一个数异或本身恒等于0,如5^5恒等于0;

2、一个数异或0恒等于本身,如5^0恒等于5。

3 满足交换律


1.交换数字
这个性质能利用与交换数字
先考虑加减改变法。
a=a+b
b=a-b;
a=a-b;;

实际上以第一个 A(与a区别)=a+b 作为临时的参数A(实际a+b) 完成
b=A-b=a+b-b=a;
a=A-a=(经过上面的运算 a==b了)=A-b;

用异或也是同理
A=a^b
b=a^b^b=a
a=A^a(经过上面的运算 a==b了)=A^b
第一个应用讨论完毕
2.hdu2095

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
1 1 3 2 2
3
1 2 1
0
 
Sample Output
3
2
Hint
Hint
use scanf to avoid Time Limit Exceeded
 

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 像水题的不错题 异或运算的更多相关文章

  1. poj 1002:487-3279(水题,提高题 / hash)

    487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 236746   Accepted: 41288 Descr ...

  2. Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~

    ->点击<- A. Summer Camp time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. BZOJ 3097: Hash Killer I【构造题,思维题】

    3097: Hash Killer I Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 963  Solved: 36 ...

  4. PHP实现类似题库抽题效果

    PHP实现类似题库抽题效果 大家好,我顾某人又回来了,最近学了一点PHP,然后就想写个简单小例子试试,于是就写了一个类似于从题库抽题的东西,大概就是先输入需要抽题的数量,然后从数据库中随机抽取题目. ...

  5. PAT乙级真题及训练题 1025. 反转链表 (25)

    PAT乙级真题及训练题 1025. 反转链表 (25) 感觉几个世纪没打代码了,真是坏习惯,调了两小时把反转链表调出来了,心情舒畅. 这道题的步骤 数据输入,数组纪录下一结点及储存值 创建链表并储存上 ...

  6. 啤酒和饮料|2014年蓝桥杯B组题解析第一题-fishers

    啤酒和饮料|2014年第五届蓝桥杯B组题解析第一题-fishers 啤酒和饮料 啤酒每罐2.3元,饮料每罐1.9元.小明买了若干啤酒和饮料,一共花了82.3元. 我们还知道他买的啤酒比饮料的数量少,请 ...

  7. 『Python题库 - 填空题』151道Python笔试填空题

    『Python题库 - 填空题』Python笔试填空题 part 1. Python语言概述和Python开发环境配置 part 2. Python语言基本语法元素(变量,基本数据类型, 基础运算) ...

  8. 洛谷 P4148 简单题 KD-Tree 模板题

    Code: //洛谷 P4148 简单题 KD-Tree 模板题 #include <cstdio> #include <algorithm> #include <cst ...

  9. 纪中10日T1 2300. 【noip普及组第一题】模板题

    2300. [noip普及组第一题]模板题 (File IO): input:template.in output:template.out 时间限制: 1000 ms  空间限制: 262144 K ...

随机推荐

  1. 数据分析系统DIY3/3:本地64位WIN7+matlab 2012b訪问VMware CentOS7+MariaDB

    数据分析系统DIY中要完毕的三个任务. 一.用VMware装64位CentOS.数据库服务端用CentOS自带的就好. 二.数据採集与预处理用Dev-C++编程解决. 三.用本地Win7 64上的MA ...

  2. Eclipse中使用正则屏蔽Logcat中的某些Tag

    在使用Eclipse进行Android真机调试的时候经常会出现满屏幕的LogCat,即使设定了根据程序分类也不行 经常会有 Dalvikvm InputMethod这样的Tag出现 给自己的应用设定T ...

  3. 免费自学Cocos2d-x3.0final2014原创视频教程(56集)(适用于Cocos2d-x3.1 Cocos2d-x3.2版本号全)

    Cocos2d-x3.0final(适用于Cocos2d-x3.1 Cocos2d-x3.2版本号全) 视频播放地址:http://yun.itxdl.cn/course/62 视频下载地址:http ...

  4. WEB服务器3--IIS7.0安装和配置

    安装Web服务器(IIS) 点击开始菜单->所有程序->管理工具->服务器管理器,启动服务器管理器,界面如下: 在服务器管理器中,选择角色,你将可以看到角色总视图. 点击添加角色,会 ...

  5. 《JavaScript 闯关记》之垃圾回收和内存管理

    JavaScript 具有自动垃圾收集机制(GC:Garbage Collecation),也就是说,执行环境会负责管理代码执行过程中使用的内存.而在 C 和 C++ 之类的语言中,开发人员的一项基本 ...

  6. Android-------- AlertDialog中EditText无法弹出输入法的解决

    文章转自:http://21jhf.iteye.com/blog/2007375: 如果AlertDialog中有编辑录入框(newMainLayout里面动态创建了EditText控件),show后 ...

  7. QQ中未读气泡拖拽消失的实现(参照一位年轻牛B的博主的思路自己实现了一下)

    原文链接:http://kittenyang.com/drawablebubble/,博主年轻却很有思想.相仿的年纪,很佩服他! 首先分析拖拽时的图,大圆.不规则的图(实际上时有规律的不然也画不出来, ...

  8. hdu 1587

    Problem Description As you know, Gardon trid hard for his love-letter, and now he's spending too muc ...

  9. (转)Eclipse Shortcuts

    原文地址: http://javapapers.com/core-java/eclipse-shortcuts/ Editors are an integral part of a programme ...

  10. MySQL 常用字段类型,介绍及其建表使用方法经验分享

    由于工作的公司没有专业的DBA又经常需要建立各种各种的表来满足自己的业务逻辑,所以经常查看MySQL 手册或者谷歌查看相关资料,所以本人就根据我的工作经验和相关资料来介绍一下MySQL各种字段类型及其 ...