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;
}
相关推荐
一轮弯弯的明月1 分钟前
有序整数对个数-欧拉函数
java·算法·蓝桥杯·学习心得
dazzle16 分钟前
机器学习算法原理与实践-入门(十):基于PaddlePaddle框架的线性回归
算法·机器学习·paddlepaddle
2501_9403152618 分钟前
【无标题】1.用哈希表做两数之和
算法·哈希算法·散列表
Yu_Lijing26 分钟前
基于C++的《Head First设计模式》笔记——访问者模式
c++·笔记·设计模式
计算机安禾30 分钟前
【数据结构与算法】第20篇:二叉树的链式存储与四种遍历(前序、中序、后序、层序)
c语言·开发语言·数据结构·c++·学习·算法·visual studio
顶点多余30 分钟前
POSIX信号量+生产消费模型应用+环形缓冲区实现
linux·c++
菜菜的顾清寒43 分钟前
力扣HOT100(16)除了自身以外数组的乘积
算法·leetcode·职场和发展
sali-tec43 分钟前
C# 基于OpenCv的视觉工作流-章45-圆卡尺
图像处理·人工智能·opencv·算法·计算机视觉
￰meteor1 小时前
【函数指针】
c++
Huangjin007_1 小时前
【C++类和对象(四)】手撕 Date 类:赋值运算符重载 + 日期计算
开发语言·c++