0
点赞
收藏
分享

微信扫一扫

A. Marin and Photoshoot

小布_cvg 2022-03-30 阅读 76
python

​​​​​​Problem - A - Codeforces

 

A. Marin and Photoshoot
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!

For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least 22 cosplayers, the number of males does not exceed the number of females (obviously).

Currently, the line has nn cosplayers which can be described by a binary string ss. The ii-th cosplayer is male if si=0si=0 and female if si=1si=1. To ensure that the line is beautiful, you can invite some additional cosplayers (possibly zero) to join the line at any position. You can't remove any cosplayer from the line.

Marin wants to know the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful. She can't do this on her own, so she's asking you for help. Can you help her?


Input

The first line contains a single integer tt (1≤t≤1031≤t≤103) — the number of test cases.

The first line of each test case contains a positive integer nn (1≤n≤1001≤n≤100) — the number of cosplayers in the initial line.

The second line of each test case contains a binary string ss of length nn — describing the cosplayers already in line. Each character of the string is either 0 describing a male, or 1 describing a female.

Note that there is no limit on the sum of nn.


Output

For each test case, print the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful.


Example
input
Copy

9
3
000
3
001
3
010
3
011
3
100
3
101
3
110
3
111
19
1010110000100000101


output
Copy

4
2
1
0
2
0
0
0
17


Note

In the first test case, for each pair of adjacent cosplayers, you can invite two female cosplayers to stand in between them. Then, 000→0110110000→0110110.

In the third test case, you can invite one female cosplayer to stand next to the second cosplayer. Then, 010→0110010→0110.

from calendar import c
import sys
import math
#import numpy as np
#sys.stdin = open("in.txt", "r")
 
T = int(input())
for _ in range(T):
    n= int(input())
    arr= input()
    last=-10
    ans=0
    for i in range(len(arr)):
        if arr[i]=='0':
            diff=i-last-1
            ans+=max(0,2-diff)
            last=i
    print(ans)
    #break


index间隔

举报

相关推荐

A. Banana

A. String Building

A. Food for Animals

A. Number Transformation

A. Subtle Substring Subtraction

A. Eating Soup 数学

0 条评论