1336: [Balkan2002]alien minimum circle coverage time limit:1 Sec Memory limit:162 mbsec Special Judge
submit:1573 solved:697
[Submit] [Status] [Discuss] Description
Gives you a n point, which allows you to draw a smallest circle that contains all the points.
Input
First give the number of points n,2<=n<=100000, and then give the coordinates xi,yi. ( -10000.0<=xi,yi<=10000.0)
Output
The radius of the output circle, and the coordinates of the center
Sample Input6
8.0 9.0
4.0 7.5
1.0 2.0
5.1 8.7
9.0 2.0
4.5 1.0
Sample Output5.00
5.00 5.00
Hintsource
1337: Minimum circle cover time limit:1 Sec Memory limit:64 MB
submit:897 solved:437
[Submit] [Status] [Discuss] Description gives the plane n points, n<=10^5. Request a circle with the smallest radius to cover the place. The first line of input gives the number n, and now n rows, two real numbers x, y for each row represent their coordinates. The output output has a minimum radius, which retains three decimal places. Sample Input4
1 0
0 1
0-1
-1 0
Sample Output1.000Hintsourcesolution
Minimum circle covering bare topic, random increment method
There is a need to pay attention to this problem, the output should not only output 2 decimal places, May WA, you can consider the direct output
Stick the courseware straight up = =
Code
#include <cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<map>#include<Set>#include<stack>#include<cstdlib>#include<string>#include<bitset>#include<iomanip>#defineINF 1000000000#defineFi first#defineSe Second#defineN 100005#defineMP (x, y) make_pair (x, y)using namespaceStd;typedefLong LongLl;typedef pair<int,int>Pii;typedefLong DoubleDouble;structvector{Doublex, y; Vector (Doublex=0,Doubley=0) {x=x,y=Y;}}; typedef vector POINT;TYPEDEF Vector<Point>Polygon;Const Doubleeps=1e- A;Const DoublePi=acos (-1.0);structline{Point P; Vector v; Doubleang; Line () {P,vector v):P (P), V (v) {ang=atan2 (v.y,v.x);} BOOL operator< (ConstLine &l)Const{returnang<L.ang;}};intDCMP (Doublex) {if(Fabs (x) <eps)return 0;Else returnx<0? -1:1;} Vectoroperator+ (Vector a,vector B) {return(Vector) {a.x+b.x,a.y+b.y});} Vectoroperator-(Vector a,vector B) {return(Vector) {a.x-b.x,a.y-b.y});} Vectoroperator* (Vector A,DoubleP) {return(Vector) {a.x*p,a.y*p}); Vectoroperator/(Vector A,DoubleP) {return(Vector) {a.x/p,a.y/p});BOOL operator< (Constvector& A,Constvector& b) {returna.x<b.x| | (a.x==b.x&&a.y<b.y);}BOOL operator== (Constvector& A,Constvector& b) {returnDCMP (a.x-b.x) = =0&&DCMP (a.y-b.y) = =0;}DoubleDot (Vector a,vector B) {returna.x*b.x+a.y*b.y;}DoubleLen (Vector A) {returnsqrt (Dot (a,a));}DoubleCross (Vector a,vector B) {returna.x*b.y-a.y*b.x;} Vector Rotate (vector A,Doublerad) {return(Vector) {A.x*cos (RAD)-a.y*sin (RAD), A.x*sin (RAD) +a.y*cos (RAD)});} Point GLI (Point p,vector v,point q,vector w) {Vector u=p-q;DoubleT=cross (w,u)/cross (V,W);returnp+v*T;} Point GLI (line A,line b) {Vector u=A.P-B.P;DoubleT=cross (b.v,u)/cross (A.V,B.V);returna.p+a.v*T;} Point Center_of_gravity (Point a,point b,point C) {point P= (a+b)/2, q= (A+C)/2; Vector v=rotate (b-a,pi/2), W=rotate (c-a,pi/2); if(DCMP (Len (v,w)) = =0)//This is the 3.1 line situation. { if(DCMP (A-B) +len (b-c)-len (a-c)) = =0) return(A+C)/2; if(DCMP (Len (a-c) +len (b-c)-len (A-b)) = =0) return(A+B)/2; if(DCMP (A-B) +len (a-c)-len (b-c)) = =0) return(B+C)/2; } returnGLI (p,v,q,w);}DoubleMin_cover_circle (Point *p,intN,point &c) {Random_shuffle (p,p+N); C=p[0]; DoubleR=0; inti,j,k; for(i=1; i<n;i++) if(DCMP (Len (C-p[i])-R) >0) {C=p[i],r=0; for(j=0; j<i;j++) if(DCMP (Len (C-p[j])-R) >0) {C= (P[i]+p[j])/2; R=len (C-P[i]); for(k=0; k<j;k++) if(DCMP (Len (C-p[k])-R) >0) {C=center_of_gravity (P[i],p[j],p[k]); R=len (C-P[i]); } } } returnR;}#defineMAXN 100010Point PO[MAXN];intMain () {Srand (20000104); intN scanf"%d",&N); for(intI=1; i<=n; i++) { Doublex, y; scanf"%LF%LF",&x,&y); Po[i-1]=Point (x, y); } point C; printf ("%lf\n", Min_cover_circle (po,n,c)); printf ("%LF%LF", C.X,C.Y); return 0;}
"bzoj-1336&1337" Alie minimum circle cover Minimum circle cover (random increment method)