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;
}
相关推荐
REDcker5 分钟前
C++ 崩溃堆栈捕获库详解
linux·开发语言·c++·tcp/ip·架构·崩溃·堆栈
WW_千谷山4_sch10 分钟前
洛谷P8653:[模板] [蓝桥杯 2017 国 C] 分考场(染色最小色数)
c++·算法·蓝桥杯·深度优先
兵哥工控13 分钟前
MFC高精度方波发生器实现
c++·mfc
汉克老师37 分钟前
GESP2025年12月认证C++五级真题与解析(判断题1-10)
c++·链表·贪心算法·排序·gesp5级·gesp五级
hk11241 小时前
【NLP/PatternRec】2026年度语义鸿沟分析与模糊模式识别基准索引 (Benchmark Index)
算法·自然语言处理·数据集·知识图谱·模式识别
hetao17338371 小时前
2025-12-31~2026-1-2 hetao1733837 的刷题笔记
c++·笔记·算法
争不过朝夕,又念着往昔1 小时前
C++AI
开发语言·c++·人工智能
敲上瘾1 小时前
C++11线程库指南:线程、锁、原子操作与并发编程实战
开发语言·c++·多线程
yyy(十一月限定版)1 小时前
算法——差分
算法
yyy(十一月限定版)1 小时前
算法——模拟
算法