HDU 2095 find your present (2) 异或的经典运用

来源:互联网 发布:淘宝手机端图片不清晰 编辑:程序博客网 时间:2024/06/01 07:34

原题链接


异或的经典应用
异或运算法则  
1. a ^ b = b ^ a 
2. a ^ b ^ c = a ^ (b ^ c) = (a ^ b) ^ c; 
3. d = a ^ b ^ c 则 a = d ^ b ^ c. 

4. a ^ b ^ a = b    

附ac代码:

#include <stdio.h>int main(){int t, a, b;while(scanf("%d", &t), t){a = 0;while(t-- && scanf("%d", &b))a ^= b;printf("%d\n", a);}return 0;}



0 0