zoukankan      html  css  js  c++  java
  • 2019中国大学生程序设计竞赛(CCPC)

    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, (1A,B<2321≤A,B<232)
    OutputFor each test case,you should output the answer and a line for each answer. 
    Sample Input

    1
    3 5

    Sample Output

    1


       由题意:找到最小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. 
      有代码:
        
    #include<iostream>
    typedef long long ll;
    using namespace std;
    int main()
    {
        ll t;
        cin>>t;
        while(t--)
        {
            ll a,b;
            cin>>a>>b;
            if((a&b)==0)
                printf("1
    ");
            else
                printf("%lld
    ",a&b);
        }
    }
  • 相关阅读:
    web 学习资源整理
    CodeSmith 学习资料收集
    常用 T_SQL 语句
    SQL Server 2000查询分析器自定义查询快捷键
    插入标识列 identity_insert
    c# 上传FTP文件
    (.Net 3.5Sp1)WebForm使用System.Web.Routing
    SPQuery.ViewAttributes
    ChatterBot之linux下安装mongodb 02
    linux端口开放指定端口的两种方法
  • 原文地址:https://www.cnblogs.com/liyexin/p/11428091.html
Copyright © 2011-2022 走看看