The main topic: give the plane n points, to find the smallest circle coverage.
Idea: The round cover problem is only related to the points on the convex hull in all points, so the convex hull is first asked, then the data range is reduced. It's probably just a little bit of logn left. This way, you can have a random wave.
First find all three points of the circle, and then find two points for the diameter of the circle.
There is a triangular circumcenter formula, it is simply not human push, and then I have the mechanism of Baidu, the results are as follows:
Do not simulate annealing ...
Example is very pit, when you figure out 2.49 2.86, do not think you are stuck, actually you write hung ...
CODE:
#include <cmath> #include <cstdio> #include <iomanip> #include <cstring> #include <iostream > #include <algorithm> #define MAX 1000010#define INF 1e15using namespace std; #define SQR (a) ((a) * (a)) struct POI nt{double X,y,alpha; Point (Double _,double __): X (_), Y (__) {}-point () {} BOOL operator < (const-point &a) const {return alpha < A.alpha; } Point operator-(const point &a) const {return point (X-A.X,Y-A.Y); } void Read () {scanf ("%lf%lf", &x,&y); } void Calc (const point &p) {alpha = atan2 (y-p.y,x-p.x); }}point[max]; int cnt;double min_x = inf,min_y = INF; Point Stack[max];int top; Double Cross (const-point &p,const-&q) {return p.x * q.y-p.y * q.x;} double Calc (const point &a,cons T point &b) {return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));} Double calcx (const point &p1,const point &p2,const Point &P3) {Double up = SQR (p1.x) * (P2.Y-P3.Y) + SQR (p2.x) * (P3.Y-P1.Y) + SQR (p3.x) * (P1.Y-P2.Y), Up-= (p1.y-p2.y) * (P2. Y-P3.Y) * (P3.Y-P1.Y);d ouble down = p1.x * (P2.Y-P3.Y) + p2.x * (P3.Y-P1.Y) + p3.x * (P1.Y-P2.Y), return up/(2 * down);} Double Calcy (const point &p1,const point &p2,const point &p3) {Double up =-(SQR (P1.Y) * (p2.x-p3.x) + SQR (p2 . Y) * (p3.x-p1.x) + SQR (p3.y) * (p1.x-p2.x)), up + = (p1.x-p2.x) * (p2.x-p3.x) * (p3.x-p1.x);d ouble down = p1.x * (P2.Y-P3.Y) + p2.x * (P3.Y-P1.Y) + p3.x * (P1.Y-P2.Y); return up/(2 * down);} Inline double Judge (double x,double y) {double re =. 0;for (int i = 0; I <= top; ++i) re = max (Re,calc (Point (x, y), Stack[i] ); return re;} int main () {CIN >> cnt; for (int i = 1; I <= cnt; ++i) Point[i]. Read (); int p; for (int i = 1; I <= cnt; ++i) if (Point[i].y < min_y) {min_y = Point[i].y; min_x = point[i].x; p = i; } else if (point[I].Y = = min_y && point[i].x < min_x) {min_x = point[i].x; p = i; } for (int i = 1; I <= cnt; ++i) if (i! = P) Point[i]. Calc (Point[p]); Sort (point + 1,point + cnt + 1); Stack[top] = point[1]; Stack[++top] = point[2]; Stack[++top] = point[3]; for (int i = 4; I <= cnt, ++i) {while (Top >= 2 && Cross (Stack[top]-stack[top-1],point[i]-stack[ TOP-1]) <= 0)--top; Stack[++top] = Point[i]; } double ans = INF; Double x,y,x,y,r; for (int i = 0; I <= top, ++i) for (int j = i + 1, j <= top; ++j) for (int k = j + 1; k <= top; ++k) {x = CALCX (Stack[i],stack[j],stack[k]); y = Calcy (stack[i],stack[j],stack[k]); R = Judge (x, y); if (R < ans) {ans = R; × = x, y = y; }} for (int i = 0; I <= top; ++i) for (int j = 0; J <= top; ++j) {r = Judge ((stack[i].x + stack[j].x)/2, STA CK[I].Y + stack[j].y)/2); if (R < ans) {ans = R X = (stack[i].x + stack[j].x)/2; Y = (stack[i].y + stack[j].y)/2;}} printf ("%.2lf%.2lf%.2lf\n", X,y,ans); return 0;}
Bzoj 2823 AHOI 2012 Signal Tower convex bag + minimum circle cover