CF1994B 题解

· · 题解

思路

我们设 x 为第 1 个 1 的位置,则可以使用 a_1\sim a_x 异或 a_{r-x+1}\sim a_r 把 a_r 取反,所以 a_x\sim a_n 都是可以随意改变的,但 a_1\sim a_{x-1} 不行。所以我们只要判断 b_1\sim b_{x-1} 是否全 0 就行。

代码

# include <bits/stdc++.h>
# define I return
# define AK 0
# define IOI ;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int t, n;
string a, b;
int main () {
    ios::sync_with_stdio (0);
    cin.tie (0);
    cout.tie (0);
    cin >> t;
    while (t --) {
        cin >> n >> a >> b;
        for (int i = 0; i < n; ++ i) {
            if (a[i] == '1')
                break ;
            if (a[i] != b[i])
                goto no;
        }
        cout << "Yes\n";
        continue ;
no:
        cout << "No\n";
    }
    I AK IOI
}