find your present (2)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/1024 K (Java/Others) Total Submission(s): 13802    Accepted Submission(s): 5194

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
 
异或运算^
目给的数据量特别大 如果之前试过用hash算的话,(既开一个1000000的数组来保存每一个数字出现得次数,然后扫描值为1的) 很可能会Memory Limit Exceeded 。 
所以才想到了用异或。 异或:就是按位比较相同则为0不同则是1; 比如 3^5, 3=011,5=101,两数按位异或后为110,即6。
偶数次出现的异或结果为0 基数次结果为1
然后 异或满足交换率。 再举一个例子。
如 数据 1 2 3 2 1 先让result=0 那么可以看成是 result^1^2^3^2^1
交换律 result^1^1^2^2^3
很明显 1^1 和 2^2 都为 0
所以最后得 result^3 =0^3 =3(二进制 101)
9867992 2013-12-20 22:29:40 Accepted 2095 218MS 256K 210 B C++ 泽泽
 #include<stdio.h>
int main()
{
int n,x,i,t,m;
while(scanf("%d",&t)!=EOF&&t)
{
scanf("%d",&n);
t--;
while(t--)
{
scanf("%d",&m);
n=m^n;
}
printf("%d\n",n);
}
return ; }

HDOJ 2095的更多相关文章

  1. find your present (2) hdoj 2095

    /* author:谦智 find your present (2) hdoj 2095 法一:用暴力 法二:用map 法三: 符号是^. 异或是个位运算符号,具体是怎么操作的请百度,这里有个特性使得 ...

  2. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  4. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  6. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  7. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  8. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

  9. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

随机推荐

  1. 第八章:Javascript函数

    函数是这样一段代码,它只定义一次,但可能被执行或调用任意次.你可能从诸如子例程(subroutine)或者过程(procedure)这些名字里对函数概念有所了解. javascript函数是参数化的: ...

  2. Android Studio快速添加Gson以及GsonFormat的使用

    目录: 一.Android Studio快速添加Gson 二.Android Studio中GsonFormat的使用 三.在线JSON校验格式化工具 一.Android Studio快速添加Gson ...

  3. sax技术操作xml

    package com.xml.zh; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers. ...

  4. 【Gym 100971A】Treasure Island

    题意 题目链接给你一个地图,'#'代表水,'.'代表陆地,'?'代表擦去的地图,可能是'#'也可能是'.'.地图中本该只有一块相连的陆地,若只有一种方案则输出确定的地图.若有多种方案,则输出‘Ambi ...

  5. BZOJ-1951 古代猪文 (组合数取模Lucas+中国剩余定理+拓展欧几里得+快速幂)

    数论神题了吧算是 1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1573 Solved: 650 [Submit ...

  6. POJ-2299 Ultra_QuickSort 线段树+逆序对数

    Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 50737 Accepted: 18595 Des ...

  7. 洛谷P1262 间谍网络

    本来只想刷道小题,没想到还有点麻烦 题目描述 由于外国间谍的大量渗入,国家安全正处于高度的危机之中.如果A间谍手中掌握着关于B间谍的犯罪证据,则称A可以揭发B.有些间谍收受贿赂,只要给他们一定数量的美 ...

  8. CodeReview Learning

    目录 . 引言 . 代码检视的指导思想 . 代码检视的内容 . 回归测试 0. 引言 代码检视(Code Review)是指软件开发人员在完成代码设计.编写.调试后展开的个人或群体性的代码阅读过程,代 ...

  9. linux java cpu 100%

    1.用top找到最耗资源的进程id [ bin]# toptop - 16:56:14 up 119 days, 6:17, 7 users, load average: 2.04, 2.07, 2. ...

  10. Laravel教程 四:数据库和Eloquent

    Laravel教程 四:数据库和Eloquent 此文章为原创文章,未经同意,禁止转载. Eloquent Database 上一篇写了一些Laravel Blade的基本用法和给视图传递变量的几种方 ...