题解:CF2092B Lady Bug

· · 题解

题目传送门

题目分析

Lady Bug 每次操作可选择索引 2 \leq i \leq n,执行两种操作之一,即交换 (a_i, b_{i-1}) 或交换 (b_i, a_{i-1}),操作次数任意。

题解

从题面我们可以看出,s_1 的奇数位不管怎么挪还是奇数位,偶数位不管怎么挪还是偶数位;s_2 的偶数位不管怎么挪都是奇数位,奇数位不管怎么挪都是偶数位。所以,我们可以看出,我们只需要统计奇偶位置 0 的个数就可以了。

Code


#include <bits/stdc++.h>

using namespace std;

char s1[200010], s2[200010];

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        cin >> (s1 + 1) >> (s2 + 1);
        int cnt_ou = 0, cnt_ji = 0;
        for (int i = 1; i <= n; i++)
        {
            if (s1[i] == '0')
            {
                if (i % 2 == 1) cnt_ji++;
                else cnt_ou++;
            }
        }
        for (int i = 1; i <= n; i++)
        {
            if (s2[i] == '0')
            {
                if (i % 2 == 1) cnt_ou++;
                else cnt_ji++;
            }
        }
        if (cnt_ou >= n / 2 && cnt_ji >= n - n / 2)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}