标签:
6 1 2 2 25 3 3 11 2 18
4 11
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 500000+5;
const int INF = 1000000000+5;
int L,n,m;
int stone[maxn];
bool judge(const int& x) {
if(x*m < L) return false;
if(x >= L) return true;
for(int i = 0;i <= n+1;i++)
if(i!=n+1&&stone[i+1]-stone[i] > x) return false;
int step = 0;
for(int i = 0,j;i < n+1;)
{
for(j = i+1;j <= n+1 && stone[j]-stone[i] <= x;) //求当前解下需要最少的步数
if(j+1 <= n+1 && stone[j+1]-stone[i] <= x) j++;
else break;
i = j;
step++;
}
return step <= m;
}
int main() {
//freopen("input.in","r",stdin);
while(~scanf("%d %d %d",&L,&n,&m))
{
stone[0] = 0;
for(int i = 1;i <= n;i++) scanf("%d",&stone[i]);
sort(stone+1,stone+n+1);
stone[n+1] = L;
int l = 0,r = L+1,mid;
while(r-l>=1)
{
mid = l+((r-l)>>1);
if(judge(mid)) r = mid;
else l = mid+1;
}
printf("%d\n",l);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
hdu 4004 The Frog's Games 【二分】
标签:
原文地址:http://blog.csdn.net/acmore_xiong/article/details/47028887