hunnu11466—找数字2

题目链接:传送门

找数字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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值