find your present (2) 2095】的更多相关文章

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,…
HDU 2095 find your present (2) 解法一:使用set 利用set,由于只有一个为奇数次,对一个数进行查询,不在集合中则插入,在集合中则删除,最后剩下的就是结果 /* HDU 2095 find your present (2) --- 水题 */ #include <cstdio> #include <set> #include <algorithm> using namespace std; int main() { #ifdef _LOC…
/* author:谦智 find your present (2) hdoj 2095 法一:用暴力 法二:用map 法三: 符号是^. 异或是个位运算符号,具体是怎么操作的请百度,这里有个特性使得他能产生一种巧方法 a^a=0 0^c=c 看到上面这个式子是否你懂了呢? 没错,例如样例 5 1 1 3 2 2 如果我们用异或运算计算就是 1^1^3^2^2 由于1^1=0 2^2=0,那么就只剩下了唯一的一个3了. 如果有3个3,那么前面偶数个3由于3^3=0,势必也会只留下一个孤单的3.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2095 解题思路:因为只有我们要求的那个数出现的次数为奇数,所以可以用位运算来做,两次异或同一个数最后结果不变,那么就可以知道异或运算相当于过滤掉了出现次数为偶数的数,最后只留下了唯一的那一个出现次数为奇数的数. 反思:位运算好陌生,好好学. #include<stdio.h> int main() { int n; long int a; while(scanf("%d",&a…
题意:找出现次数为奇数的数 xor运算 #include <cstdio> #include <iostream> #include <algorithm> using namespace std; int main() { int n; while(scanf("%d",&n),n) { int a,ans=0; for(int i=1;i<=n;i++) { scanf("%d",&a); ans^=a;…
题意:给定n个数,让你找出那一个次数为1的. 析:由于题意说了,只有那一个数是奇数,所以其他的都是偶数,根据异或的性质,两个相同的数异或为0: 任何数和0异或得原数,可以很简单的做出这个题. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring> #inc…
解题报告:输入一个n,后面紧跟着输入n个数,输入的这n个数中,除了有一个数的个数为奇数外,其它的数的个数都是偶数个,现在要你找出这个个数为奇数的这个数. 看起来好像很简单的样子,不过,这题的重点不在这里,看下内存限制就知道了,只有1024KB,也就是1M,而n的范围是1000000,输入的数的范围更是在int以内,所以这题其实考的就是一个内存优化的问题.当然,这让我们很自然的联想到中数据结构-动态链表,要多少分配多少,这样就可以最大限度的减少不必要的内存消耗.很久没写动态链表了,竟然调试了很久.…
链接:传送门 题意:给出n个数,这n个数中只有一种数出现奇数次,其他全部出现偶数次,让你找到奇数次这个数 思路:简单异或运算题 /************************************************************************* > File Name: hdu2095.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ > Created Time: 2017年…
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"…
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…