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;
}
相关推荐
ShineWinsu10 小时前
对于Qt:QFormLayout常见属性以及方法的解析
开发语言·c++·qt·面试·客户端·表单·qformlayout
kyle~11 小时前
嵌入式 SoC 系统
linux·c++·嵌入式·计算系统
罗西的思考11 小时前
【轻量化复刻大模型 / KIMI K3】Muon 优化器及 训练系统
人工智能·算法·机器学习
ashiho12 小时前
【LeetCode hot 100】3. 无重复字符的最长子串 (三种解法)
java·数据结构·后端·算法·leetcode·滑动窗口
数据工匠老o12 小时前
数据库没死,业务卡住了:行锁等待、元数据锁、长事务的排查路径
数据库·算法·架构
黑客笔记13 小时前
安全态势感知中的资产失陷排名思考
人工智能·算法·网络安全
爱写Bug的浮游14 小时前
C++移动构造真的比拷贝快吗
c++·性能优化
Aaa西红柿鸡蛋14 小时前
网络协议分析实验:基于 UDP 广播模型的 C/S 通信设计与实现
c++
青少儿编程课堂15 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:扫描线与线段树求矩形面积并解析
c++·python·算法·bfs·信息学竞赛