ABC 238 D - AND and SUM
感觉有点难啊
今天做了几道D,感觉除了DP都挺难的….
思路:
异或和加有一个性质:
因此我们可以先去判断s-2*a是不是>=0,否则就是No
然后去check x xor y
如果x xor y =1且x&y=1,那么就是非法的
不然都是合法的
Code:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxn=2e5+10;
const int mxe=5e4+10;
const int mod=998244353;
int a,s;
void solve(){
cin>>a>>s;
if(s<2*a){
cout<<"No"<<'\n';
return;
}
int p=s-2*a;
for(int j=63;j>=0;j--){
if(((p>>j)&1)&&((a>>j)&1)){
cout<<"No"<<'\n';
return;
}
}
cout<<"Yes"<<'\n';
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int __=1;cin>>__;
while(__--)solve();return 0;
}
还没有评论,来说两句吧...