The definition of this question is that a frog wants to cross the river. This one has a width, and there are several stones in the middle of the river. The frog asks to jump to the other side of the river in step m, q: Under what circumstances can a frog jump to the other side of the river, in addition, the maximum number of hops in this solution is the least (meaning that the frog's jump capability is the lowest ).
We use a binary answer to solve this problem. Its value may be in the range of 0 to the width of the river L. For a value in this range, we know the distribution of stones to determine whether this scheme is optimal, that is, to determine the maximum distance of the jump, so that the frog can jump as many stones as possible. Then, determine whether or not the specified number of steps has jumped to the other side.
The Code is as follows:
# Include <cstring>
# Include <cstdlib>
# Include <cstdio>
# Define maxn500055
Using namespace STD;
Int L, n, m, s [maxn];
Inline int CMP (const void * a, const void * B)
{
Return * (int *) A-* (int *) B;
}
Int judge (INT dis)
{// X indicates the jump x distance jump. By default, the first jump has been to X.
Int step = m, x = 0, y = 1, cur = 0;
While (step --)
{
While (DIS> = s [y]-s [x])
{
++ Y;
If (Y-1 = n + 1) // If the coordinates have jumped to the other side
Break;
}
Cur = s [Y-1];
X = Y-1;
If (cur> = L)
Break;
}
If (cur <L) // if not
Return 0;
Else
Return 1;
}
Int bsearch (int l, int R)
{
Int mid;
While (r> = L)
{
Mid = (L + r)> 1;
If (! Judge (MID ))
L = Mid + 1;
Else // The arrival will also be considered as not saturated
R = mid-1;
}
Return R + 1;
}
Int main ()
{
While (scanf ("% d", & L, & N, & M) = 3)
{
S [0] = 0;
For (INT I = 1; I <= N; ++ I)
{
Scanf ("% d", S + I );
}
S [n + 1] = L;
Qsort (S, N + 2, sizeof (INT), CMP );
Printf ("% d \ n", bsearch (0, L ));
}
Return 0;
}