A14245 | Partial Replacement
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a number $k$ and a string $s$ of length $n$ , 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 $k$ (more formally, if you replaced characters at positions $i$ and $j$ ( $i < j$ ) and at positions $[i+1, j-1]$ there is no "x" symbol, then $j-i$ must be no more than $k$ ).
For example, if $n=7$ , $s=$ .\*\*.\*\*\* and $k=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 $2$ and $6$ is greater than $k=3$ ).
Given $n$ , $k$ , and $s$ , find the minimum number of '\*' characters that must be replaced with 'x' in order to meet the above conditions.
- 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 $k$ (more formally, if you replaced characters at positions $i$ and $j$ ( $i < j$ ) and at positions $[i+1, j-1]$ there is no "x" symbol, then $j-i$ must be no more than $k$ ).
For example, if $n=7$ , $s=$ .\*\*.\*\*\* and $k=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 $2$ and $6$ is greater than $k=3$ ).
Given $n$ , $k$ , and $s$ , find the minimum number of '\*' characters that must be replaced with 'x' in order to meet the above conditions.
输入格式
The first line contains one integer $t$ ( $1 \le t \le 500$ ). Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ( $1 \le k \le n \le 50$ ).
The second line of each test case contains a string $s$ of length $n$ , consisting of the characters '.' and '\*'.
It is guaranteed that there is at least one '\*' in the string $s$ .
It is guaranteed that the distance between any two neighboring '\*' characters does not exceed $k$ .
The first line of each test case contains two integers $n$ and $k$ ( $1 \le k \le n \le 50$ ).
The second line of each test case contains a string $s$ of length $n$ , consisting of the characters '.' and '\*'.
It is guaranteed that there is at least one '\*' in the string $s$ .
It is guaranteed that the distance between any two neighboring '\*' characters does not exceed $k$ .
输出格式
For each test case output the minimum number of '\*' characters that must be replaced with 'x' characters in order to satisfy the conditions above.
输入输出样例
输入 #1
5 7 3 .**.*** 5 1 ..*.. 5 2 *.*.* 3 2 *.* 1 1 *
输出 #1
3 1 3 2 1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted