Question: There are many rest points in the zoo. If an animal rushes to the protection station, a line segment will disappear when it goes out. To create a website, the distance from the zoo to the rest point is the minimum, calculate the minimum distance and. Analysis: Calculation of ry, convex hull, Fermat point, random. First, only the vertices of the convex bag are meaningful rest stations. Then, find the fenma point of the convex bag. Here, the incremental algorithm is used to approximate the solution. Because of its monotonicity, random points in a convex hull (the reference vertex is selected here), and the control step is shortened, and the motion in the random direction is constantly approaching to the accuracy. Note: The Random Number of times is controlled, too many will be TLE, too few will WA. [Cpp] # include <algorithm> # include <iostream> # include <cstdlib> # include <cstdio> # include <cmath> # include <ctime> using namespace std; typedef struct pnode {double x, y, d; pnode (double a, double B) {x = a; y = B ;}pnode () {};} point; point Pn, P [105]; double dist (point a, point B) {return sqrt (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} double dist (point p, int N) {double sum = 0.0; (Int I = 0; I <= N; ++ I) sum + = dist (p, P [I]); return sum;} double crossproduct (point a, point B, point c) {return (B. x-a.x) * (c. y-a.y)-(c. x-a.x) * (B. y-a.y);} bool cmp1 (point a, point B) {if (. x = B. x) return. y <B. y; else return. x <B. x;} bool cmp2 (point a, point B) {return crossproduct (P [0], a, B)> 0;} bool cmp3 (point a, point B) {double cp = crossproduct (P [0],, B); if (cp = 0) {if (crossproduct (P [0], a, Pn) = 0) return. d> B. d; else return. d <B. d;} else return cp> 0;} double Graham (int N) {sort (P + 0, P + N, cmp1); sort (P + 1, P + N, cmp2); for (int I = 1; I <N; ++ I) P [I]. d = dist (P [0], P [I]); Pn = P [N-1]; sort (P + 1, P + N, cmp3); int top = N; if (N> 2) {top = 2; for (int I = 3; I <N; ++ I) {while (crossproduct (P [top-1 ], P [top], P [I]) <0) -- top; P [++ top] = P [I];} // Delete the collocated point int now = 1; for (int I = 2; I <= top; ++ I) {if (crossproduct (P [now-1], P [now], P [I]) = 0) P [now] = P [I]; else P [++ now] = P [I];} top = now;} // random incremental approximation method point t, s = P [0]; double sp = 10000.0, esp = 0.01; double temp, min = dist (s, top); while (sp> esp) {int flag = 0; for (int I = 0; I <10; ++ I) {t = s; int R = rand () % 361; t. x + = sp * cos (R); t. y + = sp * sin (R); temp = dist (t, top); if (min> temp) {min = temp; s = t; flag = 1 ;}} if (! Flag) sp/= 2.0;} return min;} int main () {srand (time (NULL); int T, N; while (scanf ("% d ", & T )! = EOF) while (T --) {scanf ("% d", & N); for (int I = 0; I <N; ++ I) scanf ("% lf", & P [I]. x, & P [I]. y); printf ("%. 0lf \ n ", Graham (N); if (T) printf (" \ n ");} return 0 ;}