.
2025-04-08 22:09:42
发布于:湖南
27阅读
0回复
0点赞
求帮调:
#include<bits/stdc++.h>
#define lop(i,a,b) for(int i(a);i<b;++i)
#define int long long
using namespace std;
template<class T>vector<vector<T>>vertices(size_t n){return vector<vector<T>>(n);}
signed main()
{
int t;
cin>>t;
while(t--)
{
int n,k;
string s;
cin>>n>>k>>s;
if(n<=k)
{
cout<<-1<<'\n';
continue;
}
vector<int>pos;
lop(i,0,n)
if(s[i]=='#')
pos.push_back(i+1);
if(pos.empty())
{
cout<<0<<'\n';
continue;
}
int l(n-k);
int r(k+1);
vector<int>sg,s_,t_;
for(int p:pos)
{
if(p>=l&&p<=r)
sg.push_back(p);
else if(p<=r)
s_.push_back(p);
else t_.push_back(p);
}
sort(s_.begin(),s_.end());
sort(t_.begin(),t_.end());
int i(0),j(0),cnt(0);
while(i<s_.size()&&j<t_.size())
{
int s(s_[i]);
int t(t_[j]);
if(t-s<=k+1&&t>s)
{
++cnt;++i;++j;
}
else if(t<s)++j;
else ++i;
}
cout<<sg.size()+cnt<<'\n';
}
}
全部评论 2
你这马峰。。。
2025-04-10 来自 浙江
0https://www.acgo.cn/application/1870763133040070656
谢谢2025-04-09 来自 浙江
0
有帮助,赞一个