ABC 238 D - AND and SUM

傷城~ 2024-03-24 01:29 160阅读 0赞

感觉有点难啊

今天做了几道D,感觉除了DP都挺难的….

7977e156ab8f4d26b221ecde9ae0728a.png

思路:

异或和加有一个性质:

0b37d3f738074d74928cf3cefc67ec6d.png

因此我们可以先去判断s-2*a是不是>=0,否则就是No

然后去check x xor y

如果x xor y =1且x&y=1,那么就是非法的

不然都是合法的

Code:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. const int mxn=2e5+10;
  5. const int mxe=5e4+10;
  6. const int mod=998244353;
  7. int a,s;
  8. void solve(){
  9. cin>>a>>s;
  10. if(s<2*a){
  11. cout<<"No"<<'\n';
  12. return;
  13. }
  14. int p=s-2*a;
  15. for(int j=63;j>=0;j--){
  16. if(((p>>j)&1)&&((a>>j)&1)){
  17. cout<<"No"<<'\n';
  18. return;
  19. }
  20. }
  21. cout<<"Yes"<<'\n';
  22. }
  23. signed main(){
  24. ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  25. int __=1;cin>>__;
  26. while(__--)solve();return 0;
  27. }

发表评论

表情:
评论列表 (有 0 条评论,160人围观)

还没有评论,来说两句吧...

相关阅读