Demo entry 6763228

mid

   

Submitted by 反对法 on Oct 20, 2018 at 13:50
Language: C++. Code size: 571 Bytes.

#include <bits/stdc++.h>

using namespace std;

const int N=1100;
const int inf=0x3f3f3f3f;
int a[N],b[N];
int main(){
	int n,r;
	scanf("%d%d",&n,&r);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int cnt=0;
	for(int i=1;i<=n;++i)
		if(a[i]==1)b[++cnt]=i;
	b[0]=-r+1;//区域[,0]
	b[cnt+1]=n+r;//区域[n+1,]
	b[cnt+2]=inf;//确保判最后路灯覆盖到n
	int ans=0;
	int pre=0;
	//cout<<cnt<<endl;
	for(int i=1;i<=cnt+1;++i){
		if(b[i+1]-b[pre]<2*r)continue;
		else if(b[i]-b[pre]<2*r){
			++ans;
			pre=i;
		}else {ans=0;break;}
	}

	cout<<ans-1<<endl;
	return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).