ACdream 1023 抑或
2016-05-28 23:38
190 查看
Xor
Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)[align=center]Submit Statistic Next Problem[/align]
Problem Description
For given multisets Aand B, find minimum non-negative xx which A⊕x=BA⊕x=BNote 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
ftiaschManager
nanae题意:集合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[100005]; int b[100005]; int exm; int sum1=0,sum2=0; int main() { int n; while(scanf("%d",&n)!=EOF) { ans1=ans2=0; sum1=0; sum2=0; for(int i=1;i<=n;i++) { scanf("%d",&exm); a[i]=exm; ans1=ans1^exm; } for(int i=1;i<=n;i++) { scanf("%d",&exm); b[i]=exm; sum2+=exm; ans2=ans2^exm; } ans1=ans1^ans2; for(int i=1;i<=n;i++) { sum1=sum1+(ans1^a[i]); } if(sum1==sum2) cout<<ans1<<endl; else cout<<"-1"<<endl; } return 0; }
相关文章推荐
- iptables(二),常用规则:屏蔽IP地址、禁用ping、协议设置、NAT与转发、负载平衡、自定义链
- 头文件和源文件的区别
- iOS 项目中出现的一些问题
- 写在前面
- 我们这一代人的困惑
- Depth-LIB-Android
- 【Java】几种面试常考排序
- Spring ProxyFactory
- malloc函数的底层实现你是否清楚
- Eclipse Java环境修复指南,Eclipse 常见小问题
- 将博客搬至CSDN
- 希尔伯特空间的科普
- iptables(一)详细教程:基础、架构、清空规则、追加规则、应用实例
- 以多态取代条件表达式
- 【Programming In Lua (2E) 笔记】2:操作lua栈
- 采用管道处理HTTP请求
- 第四百二十一天 how can I 坚持
- Android 值动画使用三
- 字典序法全排列
- Linux下安装gcc,gdb,MySQL以及vim的配置