Idea: Consider the minimum circle cover in the D height, and then go down one layer at a time to ensure that the center of the circle is the same as the first round of the answer is optimal.
Time complexity O (n)
There is a pit point, that is, I used the Srand (Time (NULL)) T, the RP is too poor.
#include <cstdio>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>#include<time.h>Const Doubleeps=1e-8;Const Doubleinf=1e60;Const DoublePi=acos (-1);structpoint{Doublex, y; Point () {}, point (DoubleX0,Doubley0): X (x0), Y (y0) {}}p[500005],o;structline{Point S,e; Line () {} line (point S0,point E0): S (s0), E (E0) {}}; Pointoperator-(Point p1,point p2) {returnPoint (p1.x-p2.x,p1.y-p2.y);} Pointoperator+(Point p1,point p2) {returnPoint (p1.x+p2.x,p1.y+p2.y);} Pointoperator* (Point P,Doublex) { returnPoint (p.x*x,p.y*x);} Pointoperator/(Point P,Doublex) { returnPoint (p.x/x,p.y/x);}Double operator*(Point p1,point p2) {returnp1.x*p2.y-p1.y*p2.x;}DoubleSqrDoublex) { returnx*x;}Doubledis (point p1) {returnsqrt (SQR (p1.x) +Sqr (P1.Y));}Doubledis (point p1,point p2) {returnDis (p1-p2);}intN;Doublecost[500005],d,r;intH;intRead () {intt=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} returnt*F;} Point Inter (line p1,line p2) {Doublek1= (P2.E-P1.S) * (p1.e-p1.s); DoubleK2= (P1.E-P1.S) * (p2.s-p1.s); Doublet= (K2)/(k1+K2); Doublex=p2.s.x+ (p2.e.x-p2.s.x) *T; Doubley=p2.s.y+ (P2.E.Y-P2.S.Y) *T; returnPoint (x, y);} Point Turn (point P,Doubleang) { Doublecos=cos (ANG); Doublesin=sin (ANG); Doublex=cos*p.x-sin*p.y; Doubley=cos*p.y+sin*p.x; returnPoint (x, y);} Point Calc (Point p1,point p2,point p3) {Point a= (P1+P2)/2.0; Point B= (P2+P3)/2.0; Point A=turn (p2-p1,pi/2.0)+A; Point B=turn (p3-p2,pi/2.0)+b; returnInter (Line (a,a), line (B,b));}intMain () {//Srand (Time (NULL)); intDD; N=read (); H=read (); scanf ("%LF", &r);DD =read (); D=DD; for(intI=0; i<=h;i++) cost[i]=read (); for(intI=1; i<=n;i++) P[i].x=read (), p[i].y=read (); for(intI=1; i<=n;i++) Std::swap (P[rand ()%n+1],p[rand ()%n+1]); O=p[1];DoubleR=0; for(intI=2; i<=n;i++) if(Dis (o,p[i]) >r+EPS) {O=p[i];r=0; for(intj=1; j<i;j++) if(Dis (o,p[j]) >r+EPS) {O= (P[i]+p[j])/2.0; R=dis (o,p[j]); for(intk=1; k<j;k++) if(Dis (o,p[k]) >r+EPS) {O=Calc (p[i],p[j],p[k]); R=dis (o,p[k]); } } } Doubleans=Inf,rr,xx,yy; inthh; H=std::min (H,DD); for(intI=0; i<=h;i++){ DoubleSxr=std::max (R,r-sqrt (SQR (D)-SQR (Double))) ; if(sxr*cost[i]<ans) {ans=sxr*Cost[i]; RR=SXR; XX=o.x; YY=o.y; HH=i; }} printf ("%.10f\n", ans); printf ("%.10f%.10f%d%.10f\n", XX,YY,HH,RR);}
Xjoi Online synchronization test DAY14 T2