hdu 4004
View Code
#include<stdio.h>
#include<algorithm>
using namespace std;
int l,n,m;
int dis[500005];
int judge(int x)
{
int now=0,pos=0,jump=0;
while(now<l)
{
now+=x;
while(now>=dis[pos+1]) pos++;
now=dis[pos];
jump++;
}
return jump;
}
int main()
{
int i,res,min;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
min=0;
for(i=1;i<=n;i++)
scanf("%d",&dis[i]);
sort(dis+1,dis+n+1);
dis[0]=0;
dis[n+1]=l;
dis[n+2]=99999999;
for(i=1;i<=n+1;i++)
if(min<dis[i]-dis[i-1])
min=dis[i]-dis[i-1];
int left=min,right=l;
while(left<=right)
{
int mid=(left+right)>>1;
if(judge(mid)<=m)
{
res=mid;
right=mid-1;
}
else left=mid+1;
}
printf("%d\n",res);
}
return 0;
}
其实题目并不难,主要是初次参加这种比赛,心态没有调整好,以为题目都很难,然后就容易把简单题目复杂化