Test instructions: There are some circles with a radius of R on the plane, and now we need to put a circle in the condition that does not intersect with the existing circle, and find the shortest distance from the center of the position where the circle can be placed.
Solution: We enlarge the radius by one times, R = 2*r, then we can put the center point on each circle or outside the circle.
First of all to put to the original point can, if not, and then all the circle of the center and the origin of the line intersection with the point in the queue, and then all the Circle 22 points of intersection into the queue, and then processing the entire queue, one judgment of these points line does not, can prove that the most advantages must be in these.
If there is a circle in the center of the (0,0) point, then a special sentence, because at this point the center and the origin of the line length of 0, for this case, we have to sentence (r,0) This is OK.
Code:
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<vector>#defineMod 1000000007#defineEPS 1e-7using namespacestd;structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {}voidInput () {scanf ("%LF%LF",&x,&y); }};typedef point Vector;structcircle{point C; DoubleR; Circle () {} circle (point C,DoubleR): C (c), R (r) {} point point (DoubleA) {returnPoint (c.x + cos (a) *r, C.y + sin (a) *R); } voidInput () {scanf ("%LF%LF%LF",&c.x,&c.y,&R); }};intDCMP (Doublex) {if(x <-eps)return-1; if(X > EPS)return 1; return 0;} Template<classT> T Sqr (t x) {returnX *x;} Vectoroperator+ (vector A, vector B) {returnVector (a.x + b.x, A.Y +b.y); }vectoroperator-(vector A, vector B) {returnVector (a.x-b.x, A.Y-b.y); }vectoroperator* (Vector A,DoubleP) {returnVector (A.x*p, a.y*p); }vectoroperator/(Vector A,DoubleP) {returnVector (a.x/p, a.y/p); }BOOL operator< (Constpoint& A,Constpoint& b) {returna.x < b.x | | (a.x = = b.x && A.y <b.y); }BOOL operator>= (Constpoint& A,Constpoint& b) {returna.x >= b.x && a.y >=b.y;}BOOL operator<= (Constpoint& A,Constpoint& b) {returna.x <= b.x && a.y <=b.y;}BOOL operator== (Constpoint& A,Constpoint& 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;}DoubleLength (Vector A) {returnsqrt (Dot (A, a));}DoubleAngle (vector A, vector B) {returnACOs (Dot (A, B)/Length (a)/Length (B)); }DoubleCross (vector A, vector B) {returna.x*b.y-a.y*b.x;}DoubleAngle (Vector v) {returnatan2 (V.Y, v.x);}BOOLInCircle (point x, Circle c) {returnDCMP (C.r-length (c.c-x)) >0; }//Not in borderintGetcirclecircleintersection (Circle C1, Circle C2, vector<point>& Sol)//number of return intersections{ DoubleD = Length (c1.c-c2.c); if(DCMP (d) = =0){ if(dcmp (C1.R-C2.R) = =0)return-1;//two round coincident return 0; } if(dcmp (C1.R + c2.r-d) <0)return 0; if(DCMP (Fabs (C1.R-C2.R)-D) >0)return 0; DoubleA = angle (c2.c-c1.c);//the polar angle of the vector c1c2 Doubleda = ACOs ((SQR (C1.R) + SQR (d)-Sqr (C2.R))/(2*C1.R*D));//c1c2 to C1p1 's anglePoint p1= C1.point (a-da), p2 = c1.point (A +da); Sol.push_back (p1); if(P1 = = p2)return 1; Sol.push_back (p2); return 2;}DoubleDISP (point P) {returnsqrt (p.x*p.x+p.y*p.y); }circle c[106],sc[106];intN;BOOLCheck (point now) { for(intI=1; i<=n;i++) { if(InCircle (Now,c[i]))return false; } return true;}intMain () {inti,j; DoubleR; while(SCANF ("%D%LF", &n,&r)!=eof && n+R) { for(i=1; i<=n;i++) {scanf ("%LF%LF", &c[i].c.x,&c[i].c.y), C[I].R =2.0*R; Sc[i]= C[i], SC[I].R =R; } Vector<Point>sec; Sec.clear (); for(i=1; i<=n;i++) { for(j=i+1; j<=n;j++) getcirclecircleintersection (C[I],C[J],SEC); } DoubleMini =Mod; if(Check (Point (0,0)) {printf ("%.6f\n",0.0);Continue; } for(i=1; i<=n;i++) { if(DCMP (DISP (c[i].c)) = =0) { if(Check (Point (2*r,0)) Mini = min (Mini,2*R); Continue; } sec.push_back (Point (c[i].c+c[i].c* (-2.0*r/DISP (C[I].C))); Sec.push_back (Point (c[i].c+c[i].c* (2.0*r/DISP (C[I].C))); } for(i=0; I<sec.size (); i++) if(check (Sec[i])) Mini =min (Mini,disp (sec[i)); printf ("%.6f\n", Mini); } return 0;}
View Code
Uvalive 4428 Solar Eclipse-Calculate geometry, Circle intersect