Increment method Minimum Circle cover ....
Maple TreesTime
limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1646 Accepted Submission (s): 510
Problem Descriptionthere is a lot of trees in HDU. Kiki want to surround all the trees with the minimal required length of the rope. As follow,
To do this problem more simple, consider all the trees is circles in a plate. The diameter of the trees is the same (the diameter of a tree is 1 unit). Kiki can calculate the minimal length of the rope, because it ' s so easy for this smart girl.
But we don ' t have a rope to surround the trees. Instead, we only have some circle rings of different radius. Now I want to know the minimal required radius of the circle ring. and I don ' t want to ask her this problem, because she's busy preparing for the examination.
As a smart Acmer, can you help me?
Inputthe input contains one or more data sets. At first line of each input data set are number of trees in the This data set N (1 <= n <=), it's followed by n coor Dinates of the trees. Each coordinate are a pair of integers, and each of the integers are in [ -1000,], it means the position of a tree ' s center. Each pair are separated by blank.
Zero at line for number of trees terminates the input for your program.
Outputminimal required radius of the circle ring I has to choose. The precision should be 10^-2.
Sample Input
21 0-1 00
Sample Output
1.50
Authorzjt
/* ***********************************************author:ckbosscreated time:2014 December 29 Monday 17:19 19 seconds file Name : hdoj2215.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;const int MAXN = 111;const double Eps=1e-8;int dcmp (double x) {if (Fabs (x) <eps) return 0;return x>eps?1:-1;} struct point{double x, y; Point () {}point (double _x,double _y) {x=_x; y=_y;}} Pt[maxn];struct circle{point C; double R; Circle () {}circle (point _c,double _r) {c=_c; r=_r;}}; Point operator+ (Point A,point B) {return point (A.X+B.X,A.Y+B.Y);} Point operator-(Point A,point B) {return point (A.X-B.X,A.Y-B.Y);} Point operator* (Point a,double p) {return point (a.x*p,a.y*p);} Point operator/(Point a,double p) {return point (a.x/p,a.y/p); }double Dot (Point A,point B) {return a.x*b.x+a.y*b.y;} Double Length (Point A) {return sqrt (Dot (a,a));} Double Cross (point A,point B) {return a.x*b.y-a.y*b.x;} Circle circumscribedcircle (Point p1,point p2,point p3) {double bx=p2.x-p1.x,by=p2.y-p1.y;double cx=p3.x-p1.x,cy= P3.y-p1.y;double d=2* (bx*cy-by*cx);d ouble cx= (cy* (bx*bx+by*by)-by* (cx*cx+cy*cy))/d+p1.x;double cy= (Bx* (Cx*Cx+Cy* Cy)-cx* (bx*bx+by*by))/d+p1.y; Point P=point (Cx,cy); return Circle (P,length (P1-p));} void Min_cover_circle (Point p[],int n,circle& c) {c.c=p[0]; c.r=0;for (int i=1;i<n;i++) {if (DCMP (p[i]-c.c )-C.R) {C.c=p[i], c.r=0;for (int j=0;j<i;j++) {if (dcmp (P[J]-C.C)-C.R) >0) {c.c=point ([p[i].x+p[j]. x)/2., (P[I].Y+P[J].Y)/2.); C.r=length (P[j]-p[i])/2.; for (int k=0;k<j;k++) {if (dcmp (Length (P[K]-C.C)-C.R) >0) {c=circumscribedcircle (p[i],p[j],p[k]);}}}}} int N;int Main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout), while (scanf ("%d", &n)!=eof&&n) {for (int i=0;i<n;i++) scanf ("%lf%lf", &pt[i].x,&pt[i].y); Circle c;min_cover_circle (pt,n,c);p rintf ("%.2lf\n", c.r+0.5);} return 0;}
Hdoj 2215 Maple trees minimum circle coverage