2019CCPC 1001
原题地址
题意:就是让你输出当(a^c)&( b ^ c)这个式子最小时候C最小值
看起来是个数学题,但其实是个水题,有多种方法做
第一种,打表找规律,然后按规律做就行
第二种,化简式子。因为^这个东西是异或的意思所以(a ^ c)可以化为(非ac)+(a非c);同理把( b ^ c),化为这种形式,之后换件就变成了(a*b) ^ c。 根据 ^ 的性质可以得到:
- 如果(a * b) 不为零的话,c就必须与它相同的时候,式子最小为零。
- 如果为零的话,c只需要为1就可以了。
附上代码
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <string.h>
#include <algorithm>
//#include <bits/stdc++.h>
#include <vector>
#define INF 999999999
# include <cstdio>
# include <cstdlib>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int main()
{
int n, m,t,k ;
scanf("%d",&t);
for(int i=1;i<=t;i++){
ll a , b;
cin >>a >>b;
ll ans = a&b;
if(!ans)
cout<<1<<endl;
else
cout<<ans<<endl;
}
return 0;
}