跳到正文

题解

CF1988B 题解

Vitamin_B约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年7月16日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟
题目
CF1988B

版本

  1. v1当前

思路

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

代码

C++
# 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
}
原文