This question was not answered in last year's online competition...
It seems that the difficulty is similar to that of the for loop.
After you have obtained the accesskey for the five binary questions, use hash to make another step.
Tutoring ....
Idea: Search for the shortest capacity of the river crossing in binary mode. Use the capability value to cross the river...
Correct judgmentAlgorithmTime complexity can save a lotCodeTime... taught ....
The original question is used for two points, and the comparison is based on the number of jumps. Later I found that it does not need to be twice ..
# Include <iostream> # include <algorithm> # define INF 0x7fffffffusing namespace STD; int L, n, m; int stone [555555]; bool canjump (int AB) {int cur = 0; For (INT I = 1; I <= m; I ++) {Int J; For (j = cur; stone [J + 1]-stone [cur] <= AB; j ++); cur = J; If (cur = N) return true;} return false ;} int main () {While (scanf ("% d", & L, & N, & M )! = EOF) {memset (stone, 0x7f, sizeof (Stone); stone [0] = 0; For (INT I = 1; I <= N; I ++) scanf ("% d", & stone [I]); stone [++ N] = L; sort (stone + 1, stone + n + 1 ); int Maxx =-1; for (INT I = 1; I <= N; I ++) Maxx = max (Maxx, stone [I]-stone [I-1]); int L = Maxx, r = L, mid; while (mid = (L + r)/2, l <r) {If (canjump (MID) r = mid; else l = Mid + 1;} printf ("% d \ n", mid);} return 0 ;}