这道题贪心做,找最大k范围内的字符 ,注意首位都要取的条件
#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;
}