309434: CF1678B1. Tokitsukaze and Good 01-String (easy version)

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Tokitsukaze and Good 01-String (easy version)

题意翻译

### 题面 给定一个长度为 $n$ 的 $0,1$ 串,如 “11001111”。将这个字符串分为“11”,“00”,“1111”,它们的长度都是偶数,我们就称这个 $0,1$ 串为好的。反之,如果分分段后每段长度不是偶数,我们就称其为不好的。 本题有多组数据,对于么组数据,输出将一个不好的 $0,1$ 串变成好的所需要的最少操作次数。 对于每次操作,可以将 $0,1$ 串中任意的“0”或“1”修改成“0”或“1”。 ### 输入格式 第一行输入一个正整数 $T$,表示数据组数。 对于每组数据,第一行为一个偶数 $n$,表示 $0,1$ 串的长度。 第二行包含一个长度为 $n$ 的 $0,1$ 串。 $1 \le t \le 10000,2 \le n \le 2 \times 10^5$ ### 输出格式 对于每个测试用例,输出一行,为最小操作数。

题目描述

This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments. Tokitsukaze has a binary string $ s $ of length $ n $ , consisting only of zeros and ones, $ n $ is even. Now Tokitsukaze divides $ s $ into the minimum number of contiguous subsegments, and for each subsegment, all bits in each subsegment are the same. After that, $ s $ is considered good if the lengths of all subsegments are even. For example, if $ s $ is "11001111", it will be divided into "11", "00" and "1111". Their lengths are $ 2 $ , $ 2 $ , $ 4 $ respectively, which are all even numbers, so "11001111" is good. Another example, if $ s $ is "1110011000", it will be divided into "111", "00", "11" and "000", and their lengths are $ 3 $ , $ 2 $ , $ 2 $ , $ 3 $ . Obviously, "1110011000" is not good. Tokitsukaze wants to make $ s $ good by changing the values of some positions in $ s $ . Specifically, she can perform the operation any number of times: change the value of $ s_i $ to '0' or '1'( $ 1 \leq i \leq n $ ). Can you tell her the minimum number of operations to make $ s $ good?

输入输出格式

输入格式


The first contains a single positive integer $ t $ ( $ 1 \leq t \leq 10\,000 $ ) — the number of test cases. For each test case, the first line contains a single integer $ n $ ( $ 2 \leq n \leq 2 \cdot 10^5 $ ) — the length of $ s $ , it is guaranteed that $ n $ is even. The second line contains a binary string $ s $ of length $ n $ , consisting only of zeros and ones. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .

输出格式


For each test case, print a single line with one integer — the minimum number of operations to make $ s $ good.

输入输出样例

输入样例 #1

5
10
1110011000
8
11001111
2
00
2
11
6
100110

输出样例 #1

3
0
0
0
3

说明

In the first test case, one of the ways to make $ s $ good is the following. Change $ s_3 $ , $ s_6 $ and $ s_7 $ to '0', after that $ s $ becomes "1100000000", it can be divided into "11" and "00000000", which lengths are $ 2 $ and $ 8 $ respectively. There are other ways to operate $ 3 $ times to make $ s $ good, such as "1111110000", "1100001100", "1111001100". In the second, third and fourth test cases, $ s $ is good initially, so no operation is required.

Input

题意翻译

### 题面 给定一个长度为 $n$ 的 $0,1$ 串,如 “11001111”。将这个字符串分为“11”,“00”,“1111”,它们的长度都是偶数,我们就称这个 $0,1$ 串为好的。反之,如果分分段后每段长度不是偶数,我们就称其为不好的。 本题有多组数据,对于么组数据,输出将一个不好的 $0,1$ 串变成好的所需要的最少操作次数。 对于每次操作,可以将 $0,1$ 串中任意的“0”或“1”修改成“0”或“1”。 ### 输入格式 第一行输入一个正整数 $T$,表示数据组数。 对于每组数据,第一行为一个偶数 $n$,表示 $0,1$ 串的长度。 第二行包含一个长度为 $n$ 的 $0,1$ 串。 $1 \le t \le 10000,2 \le n \le 2 \times 10^5$ ### 输出格式 对于每个测试用例,输出一行,为最小操作数。

加入题单

上一题 下一题 算法标签: