# ACdream-1023-Xor

189人阅读 评论(0)

Description

For given multisets A

and B, find minimum non-negative x which Ax=B

.

Note that for A={a1,a2,,an}

, Ax={a1x,a2x,,anx}.

stands for exclusive-or.

Input

The first line contains a integer n

, which denotes the size of set A (also for B

).

The second line contains n

integers a1,a2,,an, which denote the set A

.

The thrid line contains n

integers b1,b2,,bn, which denote the set B

.

(1n105

, n is odd, 0ai,bi<230

)

Output

The only integer denotes the minimum x

. Print 1 if no such x

exists.

Sample Input

3
0 1 3
1 2 3

Sample Output

2

0^x=x,如果有解，那么一定存在两两异或等于x

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
int a[100005],b[100005];
while(scanf("%d",&n)!=EOF)
{
bool flag=true;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=0;i<n;i++) scanf("%d",&a[i]);
for(int j=0;j<n;j++) scanf("%d",&b[j]);
int ans=0;
for(int i=0;i<n;i++)
ans^=a[i];
for(int j=0;j<n;j++)
ans^=b[j];
for(int i=0;i<n;i++)
a[i]^=ans;
sort(a,a+n);
sort(b,b+n);
for(int i=0;i<n;i++)
{
if(a[i]!=b[i])
flag=false;
}
if(flag) printf("%d\n",ans);
else printf("-1\n");
}
return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：60501次
• 积分：4124
• 等级：
• 排名：第7738名
• 原创：370篇
• 转载：1篇
• 译文：0篇
• 评论：2条
阅读排行
评论排行
最新评论