标签:
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.
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 )
The only integer denotes the minimum xx . Print −1−1 if no such xx exists.
3 0 1 3 1 2 3
2
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<queue> 5 #include<stack> 6 #include<cmath> 7 #define ll long long 8 #define pi acos(-1.0) 9 #define mod 1000000007 10 using namespace std; 11 int ans1,ans2; 12 int a[100005]; 13 int b[100005]; 14 int exm; 15 int sum1=0,sum2=0; 16 int main() 17 { 18 int n; 19 while(scanf("%d",&n)!=EOF) 20 { 21 ans1=ans2=0; 22 sum1=0; 23 sum2=0; 24 for(int i=1;i<=n;i++) 25 { 26 scanf("%d",&exm); 27 a[i]=exm; 28 ans1=ans1^exm; 29 } 30 for(int i=1;i<=n;i++) 31 { 32 scanf("%d",&exm); 33 b[i]=exm; 34 sum2+=exm; 35 ans2=ans2^exm; 36 } 37 ans1=ans1^ans2; 38 for(int i=1;i<=n;i++) 39 { 40 sum1=sum1+(ans1^a[i]); 41 } 42 if(sum1==sum2) 43 cout<<ans1<<endl; 44 else 45 cout<<"-1"<<endl; 46 } 47 return 0; 48 }
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5538667.html