Codeforces Round #710 (Div. 3) B. Partial Replacement(贪心)

2021-04-01 17:01:00 浏览数 (1)

这道题贪心做,找最大k范围内的字符 ,注意首位都要取的条件

代码语言:javascript复制
#include<bits/stdc  .h>
using namespace std;
#define ll long long
const int N=1e5 10;
ll t;
int main(){
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		vector<int>pos;
		for(int i=0;s[i];i  ){
			if(s[i]=='*')pos.push_back(i);
		}
		if(pos.size()<=2)cout<<pos.size()<<endl;
		else{
			/*for(int i=0;i<pos.size();i  )cout<<pos[i]<<" ";
			cout<<endl;*/
			int ans=1;
			for(int i=0;i<pos.size()-1;i  ){
				int j=i 1;
				while(j<pos.size()&&pos[j]-pos[i]<=k)j  ;
				j--;
				ans  ;
				//cout<<i<<" "<<pos[j]<<endl;
				i=j-1;
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

0 人点赞