!-- 自定制样式文件 -->

Itbegin 回家

 

 1代表百合花

0代表不能走

 

意思是这样的:

看一看a[i+b]是不是1,是1的话让青蛙移到这个位置上,i=i+x,进行下一步,如果不是的话让x--,看上一个是不是1

如果是的,再按d来走,x=d

上代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <queue>
using namespace std;
int n,m,d,x,y,s,bz;
string a;
int main(){
cin>>n>>d;
cin>>a;

for(int i=0;i<n;){
x=d; /
while(x>0){ //开始循环
if(a[i+x]=='1'){ // 如果能跳到的话
i=i+x; //到当前位置
s++; //加数
x=d;
}
else x--;
if(i>=n-1){
bz=1;break;
}
}
if(bz==1)break;

}
cout<<s;
return 0;
}

posted @ 2020-08-11 21:42  XzhouxxX  阅读(180)  评论(0编辑  收藏  举报