D. 1D Eraser

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a strip of paper s that is n cells long. Each cell is either black or white. In an operation you can take any k consecutive cells and make them all white.

Find the minimum number of operations needed to remove all black cells.

Input

The first line contains a single integer t (1≤t≤1000) --- the number of test cases.

The first line of each test case contains two integers n and k (1≤k≤n≤2⋅105) --- the length of the paper and the integer used in the operation.

The second line of each test case contains a string s of length n consisting of characters B (representing a black cell) or W (representing a white cell).

The sum of n over all test cases does not exceed 2⋅105.

Output

For each test case, output a single integer --- the minimum number of operations needed to remove all black cells.

Example

input

Copy

复制代码

8

6 3

WBWWWB

7 3

WWBWBWW

5 4

BWBWB

5 5

BBBBB

8 2

BWBWBBBB

10 2

WBBWBBWBBW

4 1

BBBB

3 2

WWW

output

Copy

复制代码
2
1
2
1
4
3
4
0

Note

In the first test case you can perform the following operations:WBWWWB→WWWWWB→WWWWWW

In the second test case you can perform the following operations:WWBWBWW→WWWWWWW

In the third test case you can perform the following operations:BWBWB→BWWWW→WWWWW

解题说明:此题是一道模拟题,每次只能修改连续K个位置,遍历查找其中的B字母位置,直接将其与后面K-1个位置全变成W即可。

cpp 复制代码
#include <stdio.h>
int main()
{
	int t, n, k, i, j, b;
	scanf("%d", &t);
	for (i = 0; i < t; i++)
	{
		scanf("%d %d", &n, &k);
		char a[200005];
		scanf("%s", a);
		b = 0;
		for (j = 0; j < n; j++)
		{
			if (a[j] == 'W')
			{
				continue;
			}
			else 
			{
				j += (k - 1); 
				b += 1; 
			}
		}
		printf("%d\n", b);
	}
	return 0;
}
相关推荐
彷徨而立4 分钟前
【C/C++】strerror、GetLastError 和 errno 的含义和区别?
c语言·c++
誰能久伴不乏28 分钟前
【Qt实战】工业级多线程串口通信:从底层协议设计到完美收发闭环
linux·c++·qt
2401_8321319532 分钟前
模板错误消息优化
开发语言·c++·算法
金枪不摆鳍32 分钟前
算法--二叉搜索树
数据结构·c++·算法
liu****35 分钟前
4.Qt窗口开发全解析:菜单栏、工具栏、状态栏及对话框实战
数据库·c++·qt·系统架构
近津薪荼36 分钟前
优选算法——双指针6(单调性)
c++·学习·算法
helloworldandy1 小时前
高性能图像处理库
开发语言·c++·算法
2401_836563181 小时前
C++中的枚举类高级用法
开发语言·c++·算法
bantinghy1 小时前
Nginx基础加权轮询负载均衡算法
服务器·算法·nginx·负载均衡
chao1898441 小时前
矢量拟合算法在网络参数有理式拟合中的应用
开发语言·算法