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);
        }
    }
  • 相关阅读:
    如何在。net中扩展本机消息框对话框
    一个显示角色映射的对话框
    键盘消息/加速器处理MFC对话框的应用程序
    立即显示WinForms使用如图所示()事件
    XFontDialog——定制CFontDialog第一部分:添加字体过滤器
    一个动画风格的对话框类
    类似vista的任务对话框
    简单而强大的可调整大小的对话框
    /etc/hosts
    /etc/sysconfig/network-scripts/ifcfg-ensxx
  • 原文地址:https://www.cnblogs.com/liyexin/p/11428091.html
Copyright © 2011-2022 走看看