• 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 }
  • 相关阅读:
    Android【开机启动】流程
    TypeC的CC、UFP、DFP、DRP
    jstl 的if else 如果否则
    Java WebService 简单实例
    ORA12514: TNS: 监听程序当前无法识别连接描述符中请求的服务解决
    Myeclipse8.5 反编译插件 jad 安装
    svn server配置与TortoiseSVN、Ankhsvn+VS使用
    Linux查看历史命令,并查询操作时间
    Eclipse Class Decompiler——Java反编译插件
    Java多线程用法解析
  • 原文地址:https://www.cnblogs.com/hsd-/p/5538667.html
Copyright © 2020-2023  润新知