A - ^&^

Bit operation is a common computing method in computer science ,Now we have two positive integers AA and BB ,Please find a positive integer CC that minimize the value of the formula (A  xor  C)  &  (B  xor  C)(A  xor  C)  &  (B  xor  C) .Sometimes we can find a lot of CC to do this ,So you need to find the smallest CC that meets the criteria .

For example ,Let's say AA is equal to 5 and BB is equal to 3 ,we can choose CC=1,3.... ,so the answer we're looking for CC is equal to 1.

If the value of the expression is 0 when C=0, please print 1. 

Input

The input file contains TT test samples.(1<=TT<=100)

The first line of input file is an integer TT.

Then the TT lines contains 2 positive integers, AA and BB, (1≤A,B<2321≤A,B<232)OutputFor each test case,you should output the answer and a line for each answer. 
Sample Input

  1. 1
  2. 3 5

Sample Output

  1. 1
  2.  
  3.    由题意:找到最小C,使(A xor C)&(B xor C)最小。根据分配律,原式=(A&B) xor C
       A,B已知,则(A&B)为固定值,又根据xor(异或)知识:同为0,异为1,则要想使原式最小,C要==(A&B)才行,因为两个数异或运算,如果两个数相同,同为0,结果最小。
    所以C=(A&B)。
      又根据题意最后一句:If the value of the expression is 0 when C=0, please print 1. 
        有代码:
        
  1. #include<iostream>
  2. typedef long long ll;
  3. using namespace std;
  4. int main()
  5. {
  6. ll t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. ll a,b;
  11. cin>>a>>b;
  12. if((a&b)==)
  13. printf("1\n");
  14. else
  15. printf("%lld\n",a&b);
  16. }
  17. }

2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 A题的更多相关文章

  1. [BFS,A*,k短路径] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 path (Problem - 6705)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6705 path Time Limit: 2000/2000 MS (Java/Others)    Mem ...

  2. [贪心,dp] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 Fishing Master (Problem - 6709)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Fishing Master Time Limit: 2000/1000 MS (Java/Othe ...

  3. 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛(8/11)

    $$2019中国大学生程序设计竞赛(CCPC)\ -\ 网络选拔赛$$ \(A.\hat{} \& \hat{}\) 签到,只把AB都有的位给异或掉 //#pragma comment(lin ...

  4. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  5. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 F题 Clever King(最小割)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  6. 【赛后总结+部分题解】2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛

    赛后总结: T:今天状态一般,甚至有点疲惫.然后12点比赛开始,和队友开始看题,从最后往前面看,发现数学题公式看不懂.然后发现队友已经双开做1001和1006了,我看着1007有人A,开始做1007. ...

  7. 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛

    传送门 A.^&^ 题意: 找到最小的正数\(C\),满足\((A\ xor\ C)\&(B\ xor \ C)\)最小. 思路: 输出\(A\&B\)即可,特判答案为0的情况 ...

  8. 【2019中国大学生程序设计竞赛-女生专场】C - Function

    原题 韦神提供的思路orz 首先一个显然的性质,所有的c可以提出来,方程变成ax^2+bx的形式 因为x的值是离散的,而m的值又不大 所以一开始让x都为1(注意!x是正整数),然后每次挑一个x让他加一 ...

  9. 2019中国大学生程序设计竞赛-女生专场(重现赛)部分题解C-Function(贪心+优先队列) H-clock(模拟)

    Function 题目链接 Problem Description wls 有 n 个二次函数 Fi(x) = aix2 + bix + ci (1 ≤ i ≤ n). 现在他想在∑ni=1xi = ...

随机推荐

  1. JAVA Random 详解

    Java中存在着两种Random函数: 一.java.lang.Math.Random; 调用这个Math.Random()函数能够返回带正号的double值,该值大于等于0.0且小于1.0,即取值范 ...

  2. 如何将dmp文件导入到Oracle

    一.概述 在将dmp文件导入到Oracle中之前,需要先创建一个orcale用户.然后使用该用户名和密码,以imp的方式将数据导入到oracle中. 二.执行步骤 1.登陆oracle数据库 a.sq ...

  3. XV6操作系统代码阅读心得(五):文件系统

    Unix文件系统 当今的Unix文件系统(Unix File System, UFS)起源于Berkeley Fast File System.和所有的文件系统一样,Unix文件系统是以块(Block ...

  4. Essay写作观点的打造

    很多留学生在Essay写作过程中经常出现的问题就是缺乏对于已有知识的新的理解,只是单纯在做文献综述(literature review)而已.要怎么样才能够体现自己的理解和自己的观点,便是今天我们讲解 ...

  5. AIDL使用绑定启动远程Service出现Service Intent must be explicit: Intent

    Intent intent = new Intent(); intent.setAction("remote.MyRemoteService.Action"); 使用AIDL调用远 ...

  6. hdu 1277 全文检索 (字典树应用)

    全文检索 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. Linux运维命令笔记一

     1.Centos 无netstat 命令 yum -y install net-toolnetstat -tunp  2.Centos防火墙 systemctl stop firewalld.ser ...

  8. HDU - 5591 ZYB's Game(博弈)

    题意:A和B两人在1~N中选数字.已知1<=X<=N,谁先选中X谁就输.每当一个人选出一个不是X的数,裁判都会说明这个数比X大还是小,与此同时,可选范围随之缩小.已知A先选,求满足能让B赢 ...

  9. 解决CGrIdCtrl合并单元格后继续拆分后的问题

    DWORD dwMergeCellCount = vMergeCells.size(); ; i < dwMergeCellCount; i++){ m_HFlexGrid.SplitCells ...

  10. windows内核安全编程书籍

    windows internals 的中文译本      windows内核原理与实现 版权声明:本文为博主原创文章,未经博主允许不得转载.