CF1506B.Partial Replacement

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a number kk and a string ss of length nn, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met:

  • The first character '*' in the original string should be replaced with 'x';
  • The last character '*' in the original string should be replaced with 'x';
  • The distance between two neighboring replaced characters 'x' must not exceed kk (more formally, if you replaced characters at positions ii and jj (i<ji \lt j) and at positions [i+1,j−1][i+1, j-1] there is no "x" symbol, then j−ij-i must be no more than kk).

For example, if n=7n=7, s=s=.**.*** and k=3k=3, then the following strings will satisfy the conditions above:

  • .xx.*xx;
  • .x*.x*x;
  • .xx.xxx.

But, for example, the following strings will not meet the conditions:

  • .**.*xx (the first character '*' should be replaced with 'x');
  • .x*.xx* (the last character '*' should be replaced with 'x');
  • .x*.*xx (the distance between characters at positions 22 and 66 is greater than k=3k=3).

Given nn, kk, and ss, find the minimum number of '*' characters that must be replaced with 'x' in order to meet the above conditions.

给你一个数字 kk 和一个长度为 nn 的字符串 ss,其中只包含字符 . 和 *。你需要将字符串中部分 * 替换为 x,使得满足以下条件:

  • 原字符串中第一个出现的 * 必须被替换为 x;
  • 原字符串中最后一个出现的 * 必须被替换为 x;
  • 任意两个相邻的被替换为 x 的字符之间的距离不能超过 kk(更准确地说:若你在位置 ii 和 jj(其中 i<ji \lt j)处替换了 x,且在区间 [i+1,j−1][i+1, j-1] 内没有其他 x,则必须满足 j−i≤kj-i \le k)。

例如,当 n=7n=7、s=s=.**.***、k=3k=3 时,以下字符串满足上述条件:

  • .xx.*xx;
  • .x*.*x*x;
  • .xx.xxx。

但以下字符串不满足条件:

  • .*.*xx(第一个 * 未被替换为 x);
  • .x*.*xx*(最后一个 * 未被替换为 x);
  • .x*.*xx(位置 22 与位置 66 上的 x 之间的距离大于 k=3k=3)。

给定 nn、kk 和 ss,求满足上述条件所需替换为 x 的 * 字符的最小数量。

输入格式

The first line contains one integer tt (1≤t≤5001 \le t \le 500). Then tt test cases follow.

The first line of each test case contains two integers nn and kk (1≤k≤n≤501 \le k \le n \le 50).

The second line of each test case contains a string ss of length nn, consisting of the characters '.' and '*'.

It is guaranteed that there is at least one '*' in the string ss.

It is guaranteed that the distance between any two neighboring '*' characters does not exceed kk.

第一行包含一个整数 tt(1≤t≤5001 \le t \le 500)。随后是 tt 组测试数据。

每组测试数据的第一行包含两个整数 nn 和 kk(1≤k≤n≤501 \le k \le n \le 50)。

每组测试数据的第二行包含一个长度为 nn 的字符串 ss,由字符 '.' 和 '*' 组成。

保证字符串 ss 中至少有一个 '*'。

保证任意两个相邻的 '*' 字符之间的距离不超过 kk。

输出格式

For each test case output the minimum number of '*' characters that must be replaced with 'x' characters in order to satisfy the conditions above.

对于每个测试用例,输出为满足上述条件所需将 * 字符替换为 x 字符的最少个数。

输入输出样例

  • 输入#1

    5
    7 3
    .**.***
    5 1
    ..*..
    5 2
    *.*.*
    3 2
    *.*
    1 1
    *

    输出#1

    3
    1
    3
    2
    1

输入解题思路,AI测评打分。不知道怎么写?

首页