首页 > 其他 > 详细

E - Red Scarf(异或)

时间:2020-07-17 19:59:11      阅读:50      评论:0      收藏:0      [点我收藏+]

链接: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;
}

 

E - Red Scarf(异或)

原文:https://www.cnblogs.com/asunayi/p/13331647.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!