HDU.2095(异或运算)
find your present (2)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) 
Total Submission(s): 21862    Accepted Submission(s): 8634
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
use scanf to avoid Time Limit Exceeded
题意分析
找出所输入n个数中出现次数为奇数的数字,并将其输出。注意此题的数字范围比较大,最大2^31,如果此时开数组的话,必然超空间,并且查找也麻烦。用异或运算较为简便。
代码总览
/*
    Title:HDU.2095
    Author:pengwill
    Date:2016-11-12
*/
#include <stdio.h>
int main()
{
    int n,temp,a;
    while(scanf("%d",&n)!= EOF && n){
        temp = 0;
        while(n--){
            scanf("%d",&a);
            temp = temp ^ a;
        }
        printf("%d\n",temp);
    }
    return 0;
}
HDU.2095(异或运算)的更多相关文章
- hdu 4768 异或运算
		
http://acm.hdu.edu.cn/showproblem.php?pid=4768 貌似非常多人是用的二分 可是更好的做法貌似还是异或 对于第k个人.假设他接到偶数个传单.那么异或的结果还是 ...
 - HDU 1287 破译密码 异或运算
		
http://acm.hdu.edu.cn/showproblem.php?pid=1287 题目: 有个叫"猪头帮"的国家,采用一种简单的文法加密,他们所用的语言里面只有大写字母 ...
 - HDU 2095 find your present (2)( 位运算 )
		
链接:传送门 题意:给出n个数,这n个数中只有一种数出现奇数次,其他全部出现偶数次,让你找到奇数次这个数 思路:简单异或运算题 /*********************************** ...
 - HDU 2095 find your present (2)
		
HDU 2095 find your present (2) 解法一:使用set 利用set,由于只有一个为奇数次,对一个数进行查询,不在集合中则插入,在集合中则删除,最后剩下的就是结果 /* HDU ...
 - HDU 5968 异或密码
		
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
 - 杭电oj 2095 & 异或^符号在C/C++中的使用
		
异或^符号,在平时的学习时可能遇到的不多,不过有时使用得当可以发挥意想不到的结果. 值得注意的是,异或运算是建立在二进制基础上的,所有运算过程都是按位异或(即相同为0,不同为1,也称模二加),得到最终 ...
 - 网络误区:不用中间变量交换2个变量的value,最高效的是异或运算.
		
本文记录了不使用中间变量交换2个变量的value,很多的网络留言说是直接异或运算就可以了,而且效率很高,是真的吗? 这里简单的说一下我的环境:Win7 32位,Qt creator 5.4.1 编译器 ...
 - C、C++、Java异或运算交换变量变量值的区别
		
今天看到一位大神的博客,深受感触.决定也发一篇博客,证明一下我还活着. 于是我翻看以前学习时做的一些笔记,整理了一下,得到了一个关于异或运算交换变量变量值的笔记. 首先来看下面三组表达式,看起来他们都 ...
 - HDOJ 1287 破译密码(异或运算)
		
Problem Description 有个叫"猪头帮"的国家,采用一种简单的文法加密,他们所用的语言里面只有大写字母,没有其他任何字符:现在还知道他们加密的方法是:只用一个大写字 ...
 
随机推荐
- ERROR: bootstrap checks failed
			
错误描述:Linux默认配置的参数过小,需要自己设置 max file descriptors [4096] for elasticsearch process is too low, increas ...
 - Python的scrapy之爬取妹子图片
			
闲来无事,做的一个小爬虫项目 爬虫主程序: import scrapy from ..items import MeiziItem class MztSpider(scrapy.Spider): na ...
 - 007---logging日志模块
			
logging模块 用途:服务器运行日志.运维日志... import logging from logging.handlers import RotatingFileHandler, TimedR ...
 - 学习CSS
			
CSS教程 菜鸟教程 通过使用CSS我们可以大大提升网页开发的工作效率 什么是CSS? CSS指层叠样式表(Cascading Style Sheets) 样式定义如何显示HTML元素 样式通常存储在 ...
 - Django调试models输出的SQL语句
			
django1.3在shell下,调试models变得更为简单了,不用像之前的版本,手工去调用django query,才能打印出之前的代码是执行的什么SQL语句. 1.3开始只需在settings. ...
 - Java:Random函数及其种子的作用
			
伪随机(preundorandom):通过算法产生的随机数都是伪随机!! 只有通过真实的随机事件产生的随机数才是真随机!!比如,通过机器的硬件噪声产生随机数.通过大气噪声产生随机数 Random生成的 ...
 - java字符流实现文件间的内容复制
			
package com.io.demo1; import java.io.FileReader; import java.io.FileWriter; public class TestFileSTr ...
 - JMeter Plugins Manager
			
JMeter插件管理器官网: https://jmeter-plugins.org/ 把jmeter-plugins-manager-0.16.jar放到C:\JMeter\apache-jmeter ...
 - MySQL☞where与like
			
1.无条件查询语句(查询表中所有数据) select * from 表名 2.查询某些列的数据(指定列) select 列名1,列名2,列名3 from 表名 3.条件查询语句 select 列名1, ...
 - selenide 自动化UI测试中Configuration全局配置项目
			
selenide 在测试过程中需要设置许多的默认值,方便在测试过程中进行和很好的使用.下面我们在selenide中的api引用过来看看! static Configuration.AssertionM ...