Files
python/TangDou/LuoGuBook/19_6.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
772 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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 = 01 ^ 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;
}