CF1988B 题解

· · 题解

思路

显然,使用操作 2 不会对 1 产生任何好处,所以我们考虑使用操作 1 把所有连续的 0 压缩成一个,最后直接判断 0,1 谁多就行。

代码

# 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, s1, s2;
string a;
int main () {
    ios::sync_with_stdio (0);
    cin.tie (0);
    cout.tie (0);
    cin >> t;
    while (t --) {
        s1 = s2 = 0;
        cin >> n >> a;
        for (int i = 0; i < n; ++ i)
            if (a[i] == '1')
                ++ s1;
            else if (! i || a[i - 1] != '0')
                ++ s2;
        cout << (s1 > s2 ? "Yes\n" : "No\n");
    }
    I AK IOI
}