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;
}
相关推荐
华农DrLai10 分钟前
什么是远程监督?怎么自动生成训练数据?
人工智能·算法·llm·prompt·知识图谱
计算机安禾11 分钟前
【数据结构与算法】第16篇:串(String)的定长顺序存储与朴素模式匹配
c语言·数据结构·c++·学习·算法·visual studio code·visual studio
AI科技星20 分钟前
基于v≡c公设的理论优化方案
c语言·开发语言·算法·机器学习·数据挖掘
江不清丶21 分钟前
垃圾收集算法深度解析:从标记-清除到分代收集的演进之路
java·jvm·算法
自然常数e32 分钟前
预处理讲解
java·linux·c语言·前端·visual studio
jllllyuz33 分钟前
小型物联网系统——家居网关设计(C语言实现)
c语言·物联网·struts
·心猿意码·36 分钟前
C++ 链接陷阱与底层溯源:ODR、inline 与匿名命名空间的那些坑
c++
金刚狼881 小时前
UUID和Name不在同一条BLE广播报文里
c++·windows
wanderist.1 小时前
从Nim游戏到SG函数
c++·算法·蓝桥杯
数据皮皮侠1 小时前
2285 上市公司组织衰退程度【Dec】2010-2024
大数据·人工智能·算法·制造