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;
}
相关推荐
moringlightyn3 分钟前
进程控制(程序替换+自定义Shell)
linux·服务器·c++·笔记·c·shell·进程
不想写笔记5 分钟前
C语言 操作符(下)
c语言·笔记
@Aurora.9 分钟前
优选算法【专题二:滑动窗口】
算法
小石头 1008614 分钟前
【Java】String类(超级详细!!!)
java·开发语言·算法
.柒宇.19 分钟前
力扣hot100---42.接雨水(java版)
java·算法·leetcode
youngee1125 分钟前
hot100-41验证二叉搜索树
算法
迈巴赫车主26 分钟前
蓝桥杯20534爆破 java
java·数据结构·算法·职场和发展·蓝桥杯
ULTRA??26 分钟前
利用运动规划库OMPL的全局路径规划ROS插件(使用informedRRTstar,AI辅助完成)
c++
坚持就完事了38 分钟前
数据结构之链表
数据结构·python·算法·链表
誰能久伴不乏40 分钟前
为什么 TCP 服务端重启会出现 “Address already in use”问题解析
linux·服务器·c语言·网络·c++·tcp/ip