题目链接:传送门
找数字2 |
Time Limit: 25000ms, Special Time Limit:50000ms, Memory Limit:32768KB |
Total submit users: 134, Accepted users: 111 |
Problem 11466 : No special judgement |
Problem description |
给定2n+1个数字,只有一个数字出现了奇数次,其余的数字都出现了偶数次,现在你需要找出出现奇数次的数字。 |
Input |
包含多组数据,每组数据第一行为一个数n(0<=n<=5000000)。接下来一行包括2n+1个数字(小于1000000000)。 |
Output |
对于每组数据,输出出现奇数次的数字. |
Sample Input |
1 1 1 1 2 1 2 1 3 3 3 1 1 2 2 3 3 4 |
Sample Output |
1 2 4 |
解题思路:所有的值取异或,结果就是那个奇数
a^a = a, a^0 = a
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int N = 10080;
const int M = 5007;
const int INF = 0x3fffffff;
const int mod = 1e9+7;
const double Pi = acos(-1.0);
const double sm = 1e-9;
int main()
{
int n,a;
while( ~scanf("%d",&n) ){
int ans = 0;
for( int i = 0 ; i < 2*n+1 ; ++i ){
scanf("%d",&a);
ans ^= a;
}
printf("%d\n",ans);
}
return 0;
}