题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004
和POJ2456比较类似,求最小的最大距离。
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<climits>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<map>
using namespace std;
const int N=100000+5;
int pos[N],dis[N];
int L,n,m;
int judge(int x)
{
int s=0,step=0,i=0;
while(s<L)
{
s+=x;
while(pos[i]<=s)
i++;
s=pos[i-1];
step++;
}
return step;
}
int main()
{
while(~scanf("%d%d%d",&L,&n,&m))
{
int i;
for(i=0; i<n; i++)
scanf("%d",&pos[i]);
int max=0;
pos[n]=L;
pos[n+1]=L*2;//这句一定要有,不然会MLE或TLE
sort(pos,pos+n);
dis[0]=pos[0];
for(i=1; i<n+1; i++)
dis[i]=pos[i]-pos[i-1];
for(i=0; i<n+1; i++)
if(max<dis[i])
max=dis[i];
if(m>n)
{
printf("%d\n",max);
continue;
}
int left,right,mid;
left=max;
right=L;
while(left<right)
{
mid=(left+right)/2;
if(judge(mid)<=m)
right=mid;
else
left=mid+1;
}
printf("%d\n",left);
}
return 0;
}