题解 CF2034B
HYdroKomide · · 题解
题意:
给定一个 0-1 串,可以把连续
思路:
错误做法:考虑把每个
考虑贪心的思想,直接从左往右推,当发现有连续
程序如下:
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
const int N=2e5+5;
int T,n,m,k;
char str[N];
int main(){
scanf("%d",&T);
while(T--){
memset(str,0,sizeof(str));
scanf("%d%d%d%s",&n,&m,&k,str+1);
int curcnt=0,ans=0;//维护curcnt作为当前连续0个数
for(int i=1;i<=n;i++){
if(str[i]=='1')curcnt=0;
else{
curcnt++;
if(curcnt==m){
ans++;
i=i+k-1;
curcnt=0;
}
}
}
printf("%d\n",ans);
}
return 0;
}