标签:位运算
题意:找出现次数不同于其他数的数。
超时了一次,后来知道了位运算。。。长见识了
0^0 =0
0^1=1
1^0=1
1^1=0
0^1^1 = 0
可以发现 任何数异或0还是他本身。
一个数异或另一个数偶数次还是他本身。
代码(位运算都600+ms):
#include <stdio.h>
#include <math.h>
int main()
{
int a, b, n;
while(scanf("%d", &n), n){
scanf("%d", &a);
n-=1;
while(n --){
scanf("%d", &b);
a = a^b;
printf("%d..", a);
}
printf("%d\n", a);
}
}hdoj 2095 find your present (2) 【位运算】,布布扣,bubuko.com
hdoj 2095 find your present (2) 【位运算】
标签:位运算
原文地址:http://blog.csdn.net/shengweisong/article/details/38726239