Xor

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

For given multisets Aand B, find minimum non-negative xx which A⊕x=BA⊕x=B

Note that for A={a1,a2,…,an}A={a1,a2,…,an} , A⊕x={a1⊕x,a2⊕x,…,an⊕x}. ⊕stands for exclusive-or.

Input

The first line contains a integer nn , which denotes the size of set AA (also for BB ).

The second line contains nn integers a1,a2,…,ana1,a2,…,an , which denote the set AA .

The thrid line contains nn integers b1,b2,…,bnb1,b2,…,bn , which denote the set BB .

(1≤n≤1051≤n≤105 , nn is odd, 0≤ai,bi<2300≤ai,bi<230 )

Output

The only integer denotes the minimum xx . Print −1−1 if no such xx exists.

Sample Input

3
0 1 3
1 2 3

Sample Output

2

Source

ftiasch

Manager

 
题意:集合A 与x抑或 得到集合B  输出最小的x  若不存在输出 -1
 
题解: 1.求抑或 满足交换律
        2.两个相同的数 抑或和为0
        3.x^0=x
        4.a^x=b 可以推出 a^b=x
       
 
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<cmath>
#define ll long long
#define pi acos(-1.0)
#define mod 1000000007
using namespace std;
int ans1,ans2;
int a[];
int b[];
int exm;
int sum1=,sum2=;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
ans1=ans2=;
sum1=;
sum2=;
for(int i=;i<=n;i++)
{
scanf("%d",&exm);
a[i]=exm;
ans1=ans1^exm;
}
for(int i=;i<=n;i++)
{
scanf("%d",&exm);
b[i]=exm;
sum2+=exm;
ans2=ans2^exm;
}
ans1=ans1^ans2;
for(int i=;i<=n;i++)
{
sum1=sum1+(ans1^a[i]);
}
if(sum1==sum2)
cout<<ans1<<endl;
else
cout<<"-1"<<endl;
}
return ;
}

最新文章

  1. MySQL引擎、索引和优化(li)
  2. js中的块作用域
  3. 简单Java类与XML之间的转换
  4. 如何快速简单上传类库到CocoaPods - 图文攻略步骤
  5. 疯狂房价&quot;逼死&quot;年轻人,别指望中国未来能出人才了
  6. MVVM架构~knockoutjs系列之正则表达式使规则更灵活
  7. Hibernate总结2 API和配置文件
  8. PXE-kickstart无人值守批量装机
  9. Gitweb 安装与配置
  10. 动态规划(模型转换):uvaoj 1625 Color Length
  11. IOS消息推送情况总结
  12. SQL Serverf 索引 - 索引压缩 、附加特性 &lt;第十篇&gt;
  13. mongodb查询关于大于小于的用法;
  14. 使用 Passenger +Apache扩展 Puppet,代替其Webrick的web框架
  15. ASP.NET Core 身份验证(一)
  16. 第45章 工具 - Identity Server 4 中文文档(v1.0.0)
  17. [模板] CDQ分治&amp;&amp;BZOJ3262:陌上花开
  18. Excel操作小结
  19. 面试:http协议
  20. windows下如何将Python文件打包成.exe可执行文件

热门文章

  1. 安装阿里云版Linux云服务器,配置软件
  2. Docker自学纪实(六)搭建docker私有仓库
  3. css页面出现滚动条左右跳动
  4. scapy--初识
  5. JDK学习---深入理解Comparator、TreeSet、TreeMap为什么可以排序
  6. Python中的not, and, or
  7. saltstack plug in
  8. [bzoj3071]N皇后
  9. c语言printf()输出格式大全(转载)
  10. MySQL权限管理创建帐户