hdu 2095 find your present(2)

find your present (2)

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

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

真坑。。。题目给的数据量过大开数组会   Memory Limit Exceeded  只能用异或

整数的异或是先把它们化成二进制,再按位异或。

比如3^5,3=011,5=101,两数按位异或后为110,即6。

几个数异或满足交换律。2^3^2=2^2^3=0^3=3.

两个相同的数异或为0,普通数都出现了偶数次,

所以它们异或后都是0,而0与那个特别数异或后还是那个特殊数。

#include<stdio.h>
int main()
{
    int n,i,x,y;
    while(scanf("%d",&n)!=EOF&&n)
    {
           x=0;
           while(n--)
           {
                scanf("%d",&y);
                x^=y;
           }
           printf("%d\n",x);
    }
    return 0;
}

hdu 2095 find your present(2)

时间: 2024-10-03 07:54:34

hdu 2095 find your present(2)的相关文章

hdu 5640 King&#39;s Cake(模拟)

Problem Description It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut

hdu 4930 Fighting the Landlords (模拟)

Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 160    Accepted Submission(s): 52 Problem Description Fighting the Landlords is a card game which has been a heat for ye

HDU 4738 Caocao&#39;s Bridges(割边)

乍一看一个模板题,仔细一看还是模板题,但是三个坑.1,不是连通图,放0个.2 守卫为0,放1个. 3注意重边. #include<iostream> #include<cstdio> #include<vector> #include<queue> #include<algorithm> #include<stack> #include<cstring> using namespace std; #define maxn

hdu 5623 KK&#39;s Number(dp)

问题描述 我们可爱的KK有一个有趣的数学游戏:这个游戏需要两个人,有N\left(1\leq N\leq 5*{10}^{4} \right)N(1≤N≤5∗10?4??)个数,每次KK都会先拿数.每次可以拿任意多个数,直到NN个数被拿完.每次获得的得分为取的数中的最小值,KK和对手的策略都是尽可能使得自己的得分减去对手的得分更大.在这样的情况下,最终KK的得分减去对手的得分会是多少? 输入描述 第一行一个数T\left( 1\leq T\leq 10\right)T(1≤T≤10),表示数据组

HDU 5624 KK&#39;s Reconstruction(最小生成树)

题目链接:点击打开链接 题意:n个城市, m条可以修建的路, 修每条路有一个费用, 要求修建路将n个城市全部联通,并且最大费用减去最小费用最小. 思路:枚举最小边, 然后重新求一遍最小生成树,复杂度m^2, 出的数据水了, 左边BC水过了.. 细节参见代码: #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #inc

hdu 4891 The Great Pan (模拟)

为什么要开__int64 巨巨在哪~ # include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int main () { __int64 count; int i,len,cot,cot1,j,flag,n; char a[1001][1030]; while(~scanf("%d",&n)) { getchar(); flag=0

hdu 4883 TIANKENG’s restaurant(暴力)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 Problem Description TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to have meal because of its delicious dishes. Today n groups of customers come t

HDU 2204 Eddy&#39;s爱好(容斥原理)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2204 解题报告:输入一个n让你求出[1,n]范围内有多少个数可以表示成形如m^k的样子. 不详细说了,自己一开始也忽略了三个素数的乘积的乘方的情况. 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6

hdu 5620 KK&#39;s Steel(推理)

Problem Description Our lovely KK has a difficult mathematical problem:he has a N(1≤N≤1018) meters steel,he will cut it into steels as many as possible,and he doesn't want any two of them be the same length or any three of them can form a triangle. I