CF1363B.Subsequence Hate

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Shubham has a binary string ss. A binary string is a string containing only characters "0" and "1".

He can perform the following operation on the string any amount of times:

  • Select an index of the string, and flip the character at that index. This means, if the character was "0", it becomes "1", and vice versa.

A string is called good if it does not contain "010" or "101" as a subsequence — for instance, "1001" contains "101" as a subsequence, hence it is not a good string, while "1000" doesn't contain neither "010" nor "101" as subsequences, so it is a good string.

What is the minimum number of operations he will have to perform, so that the string becomes good? It can be shown that with these operations we can make any string good.

A string aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters.

舒巴姆有一个二进制字符串 ss。二进制字符串是指仅包含字符 "0" 和 "1" 的字符串。

他可以对字符串执行以下操作任意多次:

  • 选择字符串中的一个下标,并翻转该下标处的字符。也就是说,若该字符为 "0",则变为 "1";反之亦然。

若一个字符串不包含 "010" 或 "101" 作为子序列,则称其为好字符串——例如,"1001" 包含 "101" 作为子序列,因此不是好字符串;而 "1000" 既不包含 "010" 也不包含 "101" 作为子序列,因此是好字符串。

为使该字符串变为好字符串,他至少需要执行多少次操作?可以证明:通过上述操作,总能将任意字符串变为好字符串。

若字符串 aa 可通过对字符串 bb 删除若干(可能为零个或全部)字符得到,则称 aa 是 bb 的一个子序列。

输入格式

The first line of the input contains a single integer tt (1≤t≤100)(1\le t \le 100) — the number of test cases.

Each of the next tt lines contains a binary string ss (1≤∣s∣≤1000)(1 \le |s| \le 1000).

输入的第一行包含一个整数 tt(1≤t≤1001\le t \le 100)—— 表示测试用例的数量。

接下来的 tt 行,每行包含一个二进制字符串 ss(1≤∣s∣≤10001 \le |s| \le 1000)。

输出格式

For every string, output the minimum number of operations required to make it good.

对于每个字符串,输出使其变为“好”字符串所需的最少操作次数。

输入输出样例

  • 输入#1

    7
    001
    100
    101
    010
    0
    1
    001100

    输出#1

    0
    0
    1
    1
    0
    0
    2

说明/提示

In test cases 11, 22, 55, 66 no operations are required since they are already good strings.

For the 33rd test case: "001" can be achieved by flipping the first character — and is one of the possible ways to get a good string.

For the 44th test case: "000" can be achieved by flipping the second character — and is one of the possible ways to get a good string.

For the 77th test case: "000000" can be achieved by flipping the third and fourth characters — and is one of the possible ways to get a good string.

在测试用例 11、22、55、66 中,无需执行任何操作,因为它们已经是“好字符串”。

对于第 33 个测试用例:“001” 可通过翻转第一个字符得到——这是获得“好字符串”的一种可能方式。

对于第 44 个测试用例:“000” 可通过翻转第二个字符得到——这是获得“好字符串”的一种可能方式。

对于第 77 个测试用例:“000000” 可通过翻转第三个和第四个字符得到——这是获得“好字符串”的一种可能方式。

输入解题思路,AI测评打分。不知道怎么写?

首页