Description
There is a river with a width of L (1≤l≤1,000,000). In the middle of the river there is N (0≤n≤20000) block of stone, the frog from the West Bank through the n stones, smooth jump to the east bank of the river. The distance from the West Bank of each stone in the middle of the river is Di (where di is greater than 0 less than L). Note: di is the distance from the starting bank.
Xiao Ming idle Nothing, want to remove the middle of the river (0≤m≤n) a stone, so that some of the distance between the stones to increase a little, so that the frog is not so easy to jump to the opposite shore.
Since there are many ways to remove M-stones, xiaoming wants to know how much the maximum distance a frog can reach if he happens to remove a rock from the river. (Frog jumps for a distance: the first stone distance between the West Bank and the river, the distance between adjacent stones in the river, and the distance between the last stone and the East bank.) Every time a frog jumps from a rock to the next rock adjacent to it.
Input
multiple sets of inputs. The first row enters L, N, and M. Next, enter n positive integers (not guaranteed to be ordered), representing the distance of the N stones from the starting bank.
Output
For the group input, the maximum value of the shortest distance in the whole jump process is removed after removing m stones.
Sample Input
5 2
2 (
17)
Sample Output
4
Hint
The minimum distance between jumps is 2 (starting from the 1th stone) before the removal of the stone. The minimum spacing is 4 after removing the stones from the starting shore of 2 and 14. (0–11–17–21–25).
Code:
#include <iostream> #include <algorithm> using namespace std;
const int size = 50002;
int d[size],l,n,m;
int Minl,maxl, ans;
BOOL Ok (int x) {int tot = 0,i = 0, t = 0;
while (i<=n) {tot = d[i++];
while (i <= N && tot < x) {//cannot be less than X, tot is less than enumerated x, must be merged tot = d[i++];
t++;//take off a stone and merge it once} if (T > M) return 0;//to use T times to satisfy the condition that the answer is x, exceeding m, not conforming to the condition equal to M, returning 0}
Plus, this sentence//At this point tot is the last of the merged values, if he is less than the enumerated answer X//and T==m (that is, you can take the opportunity to get the M block of Stone),//This situation is tot minimum, so x does not meet the criteria
if (Tot < x && M = = t) return 0;
return 1;
} void Binary () {int L = minl, r = Maxl, M;
while (L <= r) {m = (l+r)/2;//if (Ok (m)) L = m + 1, ans = m;/* continues to enumerate larger answers (the smallest value is the largest, Can be as big as possible) and record the current workable answer/else R = m-1;//enum smaller answer} int main () {int I, J,
K FreopEn ("b.in", "R", stdin);
Freopen ("Tmp.out", "w", stdout); while (scanf ("%d%d%d", &l,&n,&m)!=eof) {for (i = 0; i < N; i++) scanf ("%d", &
Amp;d[i]);
Sort (d,d+n);//sorting, calculating the spacing between stones d[n] = l;//the last block (that is, the opposite shore) distance from the beginning is L minl = Maxl = ans = d[0];
for (i = N; i > 0; i--) {D[i] = d[i]-d[i-1];//to seek the spacing of stones//printf ("%d", d[i));
if (d[i] = = 0) printf ("aaa\n"); if (d[i]<minl) Minl = d[i];//to find the minimum value in all spacing Maxl + = d[i];//The maximum spacing is the sum of Di, that is, L} Binary ()
;//Binary enumeration Answer printf ("%d\n", ans);
return 0;
}