70分蒟蒻哭晕
查看原帖
70分蒟蒻哭晕
496584
hitwhhackers楼主2021/3/21 13:22
#include <stdio.h> 
#include <string.h>
#include <vector>
#include <iostream>
using namespace std;

int main()
{
	int l,n,m;
	//cin>>l>>n>>m;
	scanf("%d %d %d",&l,&n,&m);
	//int k=scanf("%d %d %d",&l,&n,&m);
	//if(k==EOF) printf("error!");
	vector <int> a;
	a.push_back(0);//方便 
	int b[50005]={0};//用来存储是否被去掉 
	int templ;//用来存入 
	for(int i=0;i<n;i++)
	{
		scanf("%d",&templ);
		a.push_back(templ);
	}
	a.push_back(l);
	int ans=0;
	
	int dis=l/2;//二分最小距离 
	int rline=l;int lline=1;
	int cunt=0;//移除掉石头的数目 
	while(lline<=rline)
	{
		memset(b,0,50005);
		cunt=0;
		if(n==0)
		{
			printf("%d",l);
			return 0;
		}
		
		
		dis=(lline+rline)/2;
		
		for(int i=0;i<n+1;i++)//注意数量 
		{
			if(b[i]==1) continue;
			int tempi=0;
			while(a[i+1+tempi]-a[i]<dis)
			{
				if(i+tempi==n) 
				{
					cunt++;
					b[i]=1;	
					break;
				}
				
				cunt++;
				b[i+1+tempi]=1;
				tempi++;
			}
		}

		if(cunt<=m)
		{
			ans=dis;
			lline=dis+1;
		}
		else rline=dis-1;
	
			
	}	
		
	printf("%d\n",ans);	
		

	
}
2021/3/21 13:22
加载中...