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);
        }
    }
  • 相关阅读:
    Kubernetes 部署 Kafka & Zookeeper & Kafka Manager
    prometheus-operator监控traefik-Ingress组件状态
    k8s与dns--coredns的一些实战经验
    kubernetes Tekton-CI/CD 持续集成流水线
    jenkins pipeline语法
    (Go)16.Redis连接池的使用
    (Go)15.golang printf 格式化输出
    (Go)14. 如何读取YAML,JSON,INI等配置文件
    Dubbo引用Javassist外部框架
    Dubbo之Filter 原理
  • 原文地址:https://www.cnblogs.com/liyexin/p/11428091.html
Copyright © 2011-2022 走看看