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 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\n"); else printf("%lld\n",a&b); } }
2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 A题
原文:https://www.cnblogs.com/liyexin/p/11428091.html