River hopscotch
Link: Click Here ~
Question Analysis:
Given the N coordinate, fixed the start point (0) at the end point (given by the question) requires that M coordinates be deleted to maximize the minimum distance between the remaining two adjacent coordinates. Calculate the maximum value.
Train of Thought Analysis:
I don't know why I think of the value with the maximum minimum distance of the binary enumeration. Below we assume it is D. What should we do?
1. First, we can use binary to get the D.
2. According to function C: the maximum distance that can meet the conditions
# Include <iostream> # include <algorithm> # include <cstdio> # include <cstring> using namespace STD; const int maxn = 50000 + 10; const int INF = ~ 0u> 2; int N, M, L; int d [maxn]; bool C (INT d) {// determine whether the distance d meets int CNT = 0, pos = 0; For (INT I = 0; I <= N; ++ I) {If (d [I]-pos <D) ++ CNT; else Pos = d [I];} return CNT <= m;} void solve () {sort (D, D + n); D [N] = L; int lB =-1, UB = inf; while (UB-lb> 1) {// binary D int mid = (Lb + UB)/2; if (C (MID) lB = mid; else UB = mid;} printf ("% d \ n", LB);} int main () {While (~ Scanf ("% d", & L, & N, & M) {for (INT I = 0; I <n; ++ I) scanf ("% d", & D [I]); solve ();} return 0 ;}
Zookeeper
Poj river hopscotch (max value minimized)