1 条题解

  • 0
    @ 2024-5-27 15:11:11

    模拟几组样例就能明白

    xyx\to y

    101\to0 需要 &

    010\to1 需要 |

    举例:101000111010 \to 0011 中 出现 10,011\to0,0\to1 ,而在不同位置上是可以一次解决的,所以只需要统计是否发生变化。

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1E9 + 7;
    
    int main() {
        int T, n, m;
        cin >> T;
        while (T--) {
            cin >> n >> m;
            int a = 0, b = 0;
            while (n || m) {
                if (n % 2 == 1 && m % 2 == 0 && !a)
                    a++;
                if (n % 2 == 0 && m % 2 == 1 && !b)
                    b++;
                n >>= 1, m >>= 1;
            }
            cout << a + b << endl;
        }
        return 0;
    }
    
    • 1

    信息

    ID
    99
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    119
    已通过
    29
    上传者