异或= =

简介:

异或,英文为exclusive OR,缩写成xor。

运算规则:相同为1,不同为0,

1 ^ 0 == 1
1 ^ 1 == 0
0 ^ 0 == 0
0 ^ 1 == 0
// 通过观察可知,异或的结果是加法

性质:

a ^ a = 0;
a ^ 0 = a; // 二进制中加0相当于不加

题目:

There are NN Snuke Cats numbered 1,2,…,N1,2,…,N, where NN is even.

Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.

Recently, they learned the operation called xor (exclusive OR).

What is xor? For example, .

They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.

We know that the xor calculated by Snuke Cat ii, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat ii is aiai​. Using this information, restore the integer written on the scarf of each Snuke Cat.

Constraints

  • All values in input are integers.
  • 2≤N≤2000002≤N≤200000
  • NN is even.
  • 0≤ai≤1090≤ai​≤109
  • There exists a combination of integers on the scarfs that is consistent with the given information.

Input

Input is given from Standard Input in the following format:

Output

Print a line containing NN integers separated with space.

The ii-th of the integers from the left should represent the integer written on the scarf of Snuke Cat ii.

If there are multiple possible solutions, you may print any of them.

Sample 1

InputcopyOutputcopy
4
20 11 9 24
26 5 7 22
  • 5 xor 7 xor 22=205 xor 7 xor 22=20
  • 26 xor 7 xor 22=1126 xor 7 xor 22=11
  • 26 xor 5 xor 22=926 xor 5 xor 22=9
  • 26 xor 5 xor 7=2426 xor 5 xor 7=24

Thus, this output is consistent with the given information.

题意:输入一个n,然后输入n个数字,然后请输出n个数字,让他们的数字XOR的值能组成原来的数组

解题思路:其实这道题利用到了同一个数XOR偶数次等于0,这个原理,根据XOR的原理,位相同为0,不同为1,我们可以将开始输入的n个数XOR起来,然后输出的时候分别再和输入的元素XOR,就能得到新的元素。

AC代码:

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
typedef long long LL;

int a[N];

int main()
{
	int n;
	scanf("%d",&n);
	int sum = 0;
	for(int i = 0 ; i < n ; i ++)
	{
		scanf("%d",&a[i]);
		sum ^= a[i];
	}
	
	for(int i = 0 ; i < n ; i ++)  printf("%d ",sum^a[i]);
	
	return 0;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

21RGHLY

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值