首页 > 异或和
头像 AliLexiWalker
发表于 2026-04-23 00:08:36
把所有数按顺序直接异或一遍即可,因为同一个数出现偶数次会在异或中抵消为 0,最后剩下的就是出现奇数次的数字异或和。 void solve(){ int n=0,c=getchar(); while(c<'0'||c>'9')c=getchar(); while(c 展开全文
头像 小男娘
发表于 2026-04-23 00:09:31
,所以偶数个相同的数异或起来是零,奇数个相同的数异或起来是自身喵~所以答案就是所有数异或起来喵~ #include <cctype> #include <cstdio> #include <iostream> using namespace std; int R 展开全文
头像 飞鸢泛惊鸿
发表于 2026-04-23 10:43:28
import sys class read: def __init__(self): self.num=0 self.idx=0 self.bytes=b'' def get_next_byte(self): 展开全文
头像 Silencer76
发表于 2026-04-23 13:57:52
**卡常题,烂活! 注意到异或的性质, 。 所以出现次数 为偶数的数字 ,一定能凑出 组 ,可以不管它。 对于 为奇数的, 肯定是偶数,操作同上。 所以,全部异或一遍,得到的就是奇数次数的元素的异或和。 #include <iostream> using namespace s 展开全文
头像 猫萌
发表于 2022-03-11 18:26:29
异或运算满足交换律,所以我们把所有数字异或起来就好,偶数的会自己异或成0,而0异或任何数字都是其本身。 #include<bits/stdc++.h> using namespace std; int main() { int n;scanf("%d",&n); 展开全文
头像 热爱伊蕾娜
发表于 2026-04-23 08:38:08
#include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); long long ans = 0; lo 展开全文
头像 腌萝卜干
发表于 2026-04-23 10:30:09
#include <bits/stdc++.h> #define x first #define y second #define all(x) x.begin(), x.end() #define vec1(T, name, n, val) vector<T> name( 展开全文
头像 YS向阳而生
发表于 2026-04-23 13:51:56
a ^ a == 0所以无脑全部异或就行了, 偶数次的会组合成0 #include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); 展开全文
头像 已标记为作弊_歪比八卜
发表于 2026-04-25 16:48:59
#include <bits/stdc++.h> using namespace std; #define int long long //一边输入一边异或即可 因为x ^ x = 0,0 ^ x = x ,所以出现偶数次数异或和的为0,所以我们可以这样 signed main() 展开全文