#include<iostream>
#include<algorithm>
#define a_max 500002
using namespace std;
int a[a_max];
int main()
{
int n, m, i;
int l;
while(scanf("%d%d%d", &l, &n, &m) != EOF)
{
int count;
memset(a, 0, sizeof(a));
for( i=1; i <= n; i++ )
scanf("%d", &a[i]);
a[i] = l;
n += 2;
sort(a, a+n);
int first = 0, end, temp, p1, p2;
end = l;
while(end-first > 1)
{
bool p = false;
count = 0;
p1 = 0;
p2 = 1;
temp = (end+first) / 2;
while(p2 < n)
{
while(a[p2] - a[p1] <= temp && p2 < n)
p2++;
if(a[p2] - a[p1] > temp && p2-p1 ==1)
{
first = temp;
p = true;
break;
}
p1 = p2-1;
count++;
}
if(p == false)
{
if(count > m)
first = temp;
else
{
end = temp;
}
}
}
printf("%d\n", end);
}
return 0;
}hdu 4004 The Frog's Games 二分查找
最新推荐文章于 2024-08-13 10:26:25 发布
1113

被折叠的 条评论
为什么被折叠?



