Files
python/TangDou/LuoGuBook/19_6.cpp

29 lines
772 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
/**
数学表示:
a ^ a ^ b = b;
a ^ b ^ a = b;
b ^ a ^ a = b;
原理:
可用穷举法证明:
异或运算:1 ^ 1 = 0;1 ^ 0 = 1; 0 ^ 1 = 1; 0 ^ 0 = 0;
穷举: 1 ^ 1 ^ 1 = 1;
1 ^ 1 ^ 0 = 0;
1 ^ 0 ^ 1 = 0;
0 ^ 1 ^ 1 = 0;
1 ^ 0 ^ 0 = 1;
0 ^ 1 ^ 0 = 1;
0 ^ 0 ^ 1 = 1;
0 ^ 0 ^ 0 = 0;
可知任意1或0出现两次,即可抵消。 从而推广至多个位(bit)。
一个数异或同一个数两次,结果还是那个数。 且异或的顺序可变。
证明:https://www.zhihu.com/question/62003033
*/
return 0;
}