【題解】Codeforces 1491D. Zookeeper and The Infinite Zoo

【題目敘述】https://codeforces.com/contest/1491/problem/D

#include <bits/stdc++.h>
using namespace std;
 
int t, u, v;
 
int main(){
    cin >> t;
    while (t--){
        cin >> u >> v;
        if (u > v){
            cout << "NO\n";
            continue;
        }
        bool flag = true;
        int cntu = 0, cntv = 0;
        while (u || v){
            if (u&1) cntu++;
            u >>= 1;
            if (v&1) cntv++;
            v >>= 1;
            if (cntu < cntv) flag = false;
        }
        if (flag) cout << "YES\n";
        else cout << "NO\n";
    }
}
分享本文 Share with friends