The Frog ' s gamesTime
limit:2000/1000 MS (java/others) Memory limit:65768/65768 K (java/others)
Total submission (s): 3980 Accepted Submission (s): 1931
Problem DescriptionThe Annual games in frogs ' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes-to-jump. The width of the river is L (1<= l <= 1000000000). There is n (0<= n <= 500000) stones lined up on a straight line from one side to the other side of the river. The frogs can only jump through the river, but they can land on the stones. If they fall into the river, they
is out. The frogs is asked to jump at a most m (1<= m <= n+1) times. Now the frogs want to know if they want to jump across the river, at least what ability should they has. (That's the frog ' s longest jump distance).
Inputthe input contains several cases. The first line of all case contains three positive integer L, N, and M.
then n lines follow. Each of the stands for the distance from the starting banks to the Nth stone, and both stone appear in one place is impossible.
Outputfor each case, output an integer standing for the frog ' s ability at least they should has.
Sample Input
6 1 2225 3 311 218
Sample Output
411
Analysis: First put the stone sort side, then use the two-point enumeration (0~l) frog jumping distance, walk out the minimum value code example that satisfies the condition: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace Std;
int num[600000];
int main ()
{
int l,n,m,i;
while (~SCANF ("%d%d%d", &l,&n,&m))
{
for (i=0;i<n;i++)
scanf ("%d", &num[i]);
Sort (num,num+n);
if (num[n-1]!=l)
Num[n++]=l;
int L=0,r=l+1,mid,sum,h,flag;
while (L<R)
{
Mid= (L+R)/2;
flag=0;
if (mid>=num[0]&&mid>= (Num[n-1]-num[n-2]))
{
Sum=1;
H=mid;
for (i=0;i<n;i++)
{
if (mid==9)
printf ("%d\n", h);
if (H>=num[i]) continue;
Else
{
sum++;
H=num[i-1]+mid;
if (sum>m| | H<num[i])
Break
}
}
printf ("i=%d\n", I);
if (i>=n)
{
flag=1;
}
}
if (flag)
{
R=mid;
}
Else
{
l=mid+1;
}
}
printf ("%d\n", L);
}
return 0;
}
Hdu 4004 The Frog ' s games "two points"