题意:给两个数,问你存不存在k使n+m==n异或m
思路:
为了让n+m==n异或m成功,很明显有两个数在同一位上最多只能有1个1。因为如果有两个就会导致数字变小,很明显n==m是不可能成功的,因为你怎么搞都会有至少一个一模一样的1,所以n==m,答案是-1
其余的让最大值构造成100000……,另外一个数因为小于这个数,所以一定构造不成一样。
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e6+10;
const int INF = 1e12;
const int MOD = 998244353;void solve(){int n,m;cin >> n >> m;if(n!=m){cout << (1ll<<30)-max(n,m) << endl;}else cout << -1 << endl;
}signed main() {IOS;int t = 1;cin >> t;while (t--) {solve();}}
反思:真的有被坑到,还是太打开思路了,构造十分简单结果想不到,反思啊反思,对于问题的转化还不够透彻