欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1678B1.Tokitsukaze and Good 01-String (easy version)
Tokitsukaze and Good 01-String (easy version)
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 of length , consisting only of zeros and ones, is even.
Now Tokitsukaze divides into the minimum number of contiguous subsegments, and for each subsegment, all bits in each subsegment are the same. After that, is considered good if the lengths of all subsegments are even.
For example, if is "11001111", it will be divided into "11", "00" and "1111". Their lengths are , , respectively, which are all even numbers, so "11001111" is good. Another example, if is "1110011000", it will be divided into "111", "00", "11" and "000", and their lengths are , , , . Obviously, "1110011000" is not good.
Tokitsukaze wants to make good by changing the values of some positions in . Specifically, she can perform the operation any number of times: change the value of to '0' or '1'(). Can you tell her the minimum number of operations to make good?
Input
The first contains a single positive integer () — the number of test cases.
For each test case, the first line contains a single integer () — the length of , it is guaranteed that is even.
The second line contains a binary string of length , consisting only of zeros and ones.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print a single line with one integer — the minimum number of operations to make good.
Note
In the first test case, one of the ways to make good is the following.
Change , and to '0', after that becomes "1100000000", it can be divided into "11" and "00000000", which lengths are and respectively. There are other ways to operate times to make good, such as "1111110000", "1100001100", "1111001100".
In the second, third and fourth test cases, is good initially, so no operation is required.
Samples
5
10
1110011000
8
11001111
2
00
2
11
6
100110
3
0
0
0
3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |