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 ;
}

ACdream 1023 抑或的更多相关文章

  1. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

  2. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  3. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

  4. acdream.A Very Easy Triangle Counting Game(数学推导)

    A - A Very Easy Triangle Counting Game Time Limit:1000MS     Memory Limit:64000KB     64bit IO Forma ...

  5. acdream.Bet(数学推导)

    Bet Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Status Pra ...

  6. acdream.郭式树(数学推导)

    郭式树 Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit Status Pr ...

  7. ACdream 1188 Read Phone Number (字符串大模拟)

    Read Phone Number Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Sub ...

  8. ACdream 1195 Sudoku Checker (数独)

    Sudoku Checker Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  9. ACdream 1112 Alice and Bob(素筛+博弈SG函数)

    Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit ...

随机推荐

  1. Linux文件系统与目录结构

    在Linux系统中,目录被组织成一个:单根倒置树结构,文件系统从根目录开始,用/来表示.文件名称区分大小写( 大小写敏感还需要看具体的文件系统格式 ),以.开头的为隐藏文件,路径用/来进行分割(win ...

  2. 利用python在windows环境下爬取赶集网工作信息。

    主要用到了多进程和多线程的知识,最后结果保存成csv文件格式,如有需要可改成数据库版本. 对用到的库做下简要介绍,具体请参考官方文档: xpinyin.Pinyin:将输入的中文转成拼音 concur ...

  3. Pagehelper介绍

    本文引自:https://my.oschina.net/zudajun/blog/745232 摘要: com.github.pagehelper.PageHelper是一款好用的开源免费的Mybat ...

  4. 关于ZYNQ-700是否支持大容量SD卡汇报

    关于ZYNQ-700是否支持大容量SD卡 不支持. 下午问了客服的FAE给的答案是不清楚,我自己调研了一下为什么. 调查结果: 1. 大容量的SD卡为什么不支持? SD2.0规范中(SDHC)硬件支持 ...

  5. Urllib库:python内置的http请求库

    1.四个模块: request error parse robotparser 2.urlopen(url, data, timeout) 发送请求 get请求无data: post请求有data 3 ...

  6. python 函数复习

    # 函数 # 可读性强 复用性强 # def 函数名(): # 函数体 #return 返回值 # 所有的函数 只定义不调用就一定不执行 #先定义后调用 #函数名() #不接收返回值 #返回值 = 函 ...

  7. Unity Occlusion Culling 遮挡剔除研究

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/52684127 作者:car ...

  8. JSP---JSTL核心标签库的使用

    JSTL 核心标签库标签共有13个,功能上分为4类: 1.表达式控制标签:out.set.remove.catch 2.流程控制标签:if.choose.when.otherwise 3.循环标签:f ...

  9. Codeforces 771E Bear and Rectangle Strips DP

    题意: 一个由大写字母组成的长度为\(n(n \leq 75)\)的字符串,每次操作可以交换相邻位置的两个字母,求最少操作多少次使字符串中不出现子串VK 分析: VK之外的字母具体是什么,我们并不关心 ...

  10. LinkedHashMap和HashMap的比较使用 详解

    由于现在项目中用到了LinkedHashMap,并不是太熟悉就到网上搜了一下. import java.util.HashMap; import java.util.Iterator; import ...