链接:https://atcoder.jp/contests/abc171/tasks/abc171_e
题意:已知a1,a2,...,an,n为偶数,定义xor为:某二进制位上有奇数个1,则该位位1,否则为0 ( 其实就是异或 ) ;a1=b2xorb3xor...xorbn, a2=b1xorb3xor...xorbn,.....,求b1,.....,bn
分析知奇数个a进行xor运算a xor a xor .... xor a=a,令tot=a1^a2^.....an,所以b1=tot^a1,b2=tot^a2...
代码
#include <bits/stdc++.h> using namespace std; const int maxn=2e5+5; int a[maxn],b[maxn]; int tot; int main(){ int n;cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; tot^=a[i]; } for(int i=0;i<n;i++){ b[i]=a[i]^tot; cout<<b[i]<<‘ ‘; } return 0; }
原文:https://www.cnblogs.com/asunayi/p/13331647.html