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;
}
相关推荐
2501_941235511 分钟前
C++与机器学习框架
开发语言·c++·算法
CoovallyAIHub3 分钟前
基于SimCLR的自监督 YOLO:YOLOv5/8也能在低标注场景目标检测性能飙升
深度学习·算法·计算机视觉
Shylock_Mister10 分钟前
ARM与x86交叉编译实战排错指南
linux·c语言·arm开发
2501_9411118617 分钟前
C++模块化设计原则
开发语言·c++·算法
2501_9412375327 分钟前
基于C++的游戏引擎开发
开发语言·c++·算法
_OP_CHEN33 分钟前
算法基础篇:(十)贪心算法拓展之哈夫曼编码:从 “合并最优” 到数据压缩的传奇
c++·算法·贪心算法·蓝桥杯·哈夫曼编码·算法竞赛·acm/icpc
枫叶丹436 分钟前
【Qt开发】Qt窗口(二) -> QToolBar工具栏
开发语言·数据库·c++·qt
l1t42 分钟前
利用DuckDB列表一句SQL输出乘法口诀表
数据库·sql·算法·duckdb
一只会写代码的猫1 小时前
深度解析 Java、C# 和 C++ 的内存管理机制:自动 vs 手动
java·jvm·算法
高山有多高1 小时前
堆应用一键通关: 堆排序 +TOPk问题的实战解析
c语言·数据结构·c++·算法