• ACdream 1023 抑或


    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 Ax=BA⊕x=B

    Note that for A={a1,a2,,an}A={a1,a2,…,an} , Ax={a1x,a2x,,anx}. 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 .

    (1n1051≤n≤105 , nn is odd, 0ai,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
           
     
     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 }
  • 相关阅读:
    Bean的装配
    什么是脏读,不可重复读,幻读
    MySQL 中的数据类型介绍
    spring事务
    js:防抖动与节流
    React 之容器组件和展示组件相分离解密
    Java 里如何实现线程间通信
    线程之间的通信
    NIO之Buffer的clear()、rewind()、flip()方法的区别
    清空git缓存
  • 原文地址:https://www.cnblogs.com/hsd-/p/5538667.html
Copyright © 2020-2023  润新知