This is a search problem, we can easily get the target value of the upper and lower bounds, and then only enumerated.
is to sort the points on the x-axis after each point from left to right, with each point either at the left end of the segment or at the right end of the segment.
The point number from 0 to n-1, starting from the point numbered 1, compresses the upper bound in the process of enumeration, there is a situation that needs to be discussed specifically, which one of the segments exactly covers the adjacent two points.
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <map>5#include <string>6#include <vector>7#include <Set>8#include <cmath>9#include <ctime>Ten #pragmaComment (linker, "/stack:102400000,102400000") One #defineLson (U << 1) A #defineRson (U << 1 | 1) - #defineRep (I, A, b) for (i = A; I < b; i++) - #defineReps (I, A, B, c) for (i = A; I < b; i + = c) the #defineRepI (I, A, b) for (i = A; I >= b; i--) - #defineCLS (i, J) memset (i, J, sizeof i) - using namespacestd; - typedef __int64 LL; + Const DoubleEPS = 1e-6; - Const DoublePI = ACOs (-1.0); + Const intMAXN = 1e5 +Ten; A Const intMAXM =1050; at Const intINF =0x3f3f3f3f; - Constll linf =0x3fffffffffffffff; - Constll mod = 1e9 +7; - - Doublea[ -]; - intN; in Doublemaxi, mini; - to DoubleDfsintUintPreDoubleLimitint fixed){ + //printf ("%d%d\n", u, pre); - if(U >= N-1)returnlimit; the if(Limit <= Mini)returnMini; * DoubleTo_left = A[u]-A[pre]; $ DoubleTo_right = A[u +1] -A[u];Panax Notoginseng Doubletem; - if(fixed){ the if(To_left >= limit)returnDFS (U +1, u, limit,1); + if(To_right >=2* limit | | To_right = = limit)returnDFS (U +2, U +1, Limit,1); A if(To_right > Limit)returnDFS (U +1, U +1, Limit,1); the if(To_right < limit)returnMini; + } - if(To_left >= limit)returnDFS (U +1, u, limit,0); $ DoubleTEM1 = DFS (U +1, U, To_left,0); $ DoubleTEM2 =Mini; - if(To_right >=2* limit) tem2 = DFS (U +2, U +1, Limit,0); - Else{ the if(to_right <= limit) tem2 = DFS (U +2, U +1, To_right,1); - DoubleTEM3 =Mini;Wuyi if(Limit >= to_right/2) Tem3 = DFS (U +2, U +1, To_right/2,0); theTEM2 =Max (tem2, tem3); -TEM3 = DFS (U +1, U +1, Min (to_right, limit),0); WuTEM3 =Max (tem2, tem3); - if(Limit < to_right/2) Tem3 = DFS (U +2, U +1, Limit,0); AboutTEM2 =Max (tem2, tem3); $ } - returnMax (tem1, tem2); - } - A intMain () { + //freopen ("In.txt", "R", stdin); the intT; -scanf"%d", &T); $ while(t--){ thescanf"%d", &n); the inti; theRep (I,0, N) scanf ("%LF", &a[i]); theSort (A, A +n); -A[n] =0; inMini = (Double) Linf; theRep (I,1, n) Mini = min (Mini, A[i]-a[i-1]); theMaxi = (Double) Linf; AboutRep (I,1N1) maxi = min (Maxi, max (A[i +1]-a[i], A[i]-a[i-1])); the DoubleAns = DFS (1,0, Maxi,0); theprintf"%.3f\n", ans); the } + return 0; -}
View Code
hdu4932 Miaomiao ' s Geometry