Maple Trees (minimum cover circle)

Source: Internet
Author: User

Maple Trees
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 222 Accepted Submission (s): 79
problem Description There 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 make 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 has 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 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
Recommendlcy
/*Test instructions: give you scattered points, let you find the smallest circle, the points around, point can be on the circle, the minimum radius of the output circle. Initial thinking: Find the convex hull, and then find out the convex hull of the circumscribed circle, two edges of the intersection of the perpendicular bisector is the center # Error: A little naïve, the triangle must have circumscribed circle, but the polygon is not necessarily circumscribed circle # Improvement: To find the convex hull, and then to find the smallest cover circle, this noun is also see the blog to Know (woo , and one less chance to have a good brain. Then the maximum radius of the circumscribed circle of any three-point triangle is just the radius of the convex hull "circumscribed circle", the circumscribed circle radius of the triangle is abc/4s, the formula can be easily proved. All radii are traversed, and the longest radius in the middle is the required radius.       #改进错误点: The above situation only applies to acute triangle, obtuse angle, right triangle "circumscribed circle" of the minimum radius, not the radius of circumscribed circle, but the longest side of the half! */#include<bits/stdc++.h>using namespacestd;/**************************** Convex package template *******************************/Const DoubleEPS = 1e-8;intSgnDoublex) {    if(Fabs (x) < EPS)return 0; if(X <0)return-1; Else return 1;}structpoint{Doublex, y; Point () {}, point (Double_x,Double_y) {x= _x;y =_y; } Pointoperator-(ConstPoint &b)Const    {        returnPoint (X-b.x,y-b.y); }    //Cross Product    Double operator^(ConstPoint &b)Const    {        returnx*b.y-y*b.x; }    //dot Product    Double operator*(ConstPoint &b)Const    {        returnx*b.x + y*b.y; }    voidinput () {scanf ("%LF%LF",&x,&y); }};structLine {point s,e; Line () {} line (point _s,point _e) {s= _s; E =_e; }}; //* Distance between two pointsDoubleDist (Point A,point b) {returnsqrt (A-B) * (Ab));} /** Find convex hull, Graham algorithm * point number 0~n-1* return convex hull result Stack[0~top-1] is the number of the convex hull*/Const intMAXN = the; Point LIST[MAXN];intSTACK[MAXN];//the point used to store the convex hullintTop//indicates the number of midpoints in the convex hull//Polar Order relative to list[0]BOOL_cmp (Point p1,point p2) {DoubleTMP = (p1-list[0]) ^ (p2-list[0]); if(SGN (TMP) >0)        return true; Else if(SGN (tmp) = =0&& sgn (Dist (p1,list[0])-Dist (p2,list[0])) <=0)        return true; Else         return false;}voidGraham (intN)    {Point p0; intK =0; P0= list[0]; //find the bottom one .     for(inti =1; I < n;i++)    {        if((P0.y > list[i].y) | | (P0.y = = List[i].y && p0.x >list[i].x)) {P0=List[i]; K=i; }} swap (list[k],list[0]); Sort (List+1, list+n,_cmp); if(n = =1) {Top=1; stack[0] =0; return; }    if(n = =2) {Top=2; stack[0] =0; stack[1] =1; return ; } stack[0] =0; stack[1] =1; Top=2;  for(inti =2; I < n;i++)    {         while(Top >1&& SGN (list[stack[top-1]]-list[stack[top-2]]) ^ (list[i]-list[stack[top-2]]) <=0) Top--; Stack[top++] =i; }}/**************************** Convex package template *******************************/intN;intMain () {//freopen ("In.txt", "R", stdin);     while(SCANF ("%d", &n)!=eof&&N) {         for(intI=0; i<n;i++) {list[i].input (); }//enter a little bit of the coordinates        if(n==1) {printf ("0.50\n"); Continue; }        if(n==2) {printf ("%.2lf\n", Dist (list[0],list[1])/2+0.5); Continue; } Graham (n);//Find out convex bag        Doublemaxr=-1.0; //cout<<top<<endl; //Static[0] As the public vertex of all small triangles         for(intI=0; i<top;i++) {//enumerating the points of a triangle             for(intj=i+1; j<top;j++){                 for(intk=j+1; k<top;k++){                    /*length of three sides*/                    DoubleA=Dist (list[stack[i]],list[stack[j]); Doubleb=Dist (list[stack[i]],list[stack[k]); DoubleC=Dist (list[stack[k]],list[stack[j]); if(a*a+b*b<c*c| | a*a+c*c<b*b| | B*b+c*c<a*a) {//Judging is not acute triangleMaxr=max (Maxr,max (max (b), C)/2); }Else{                        /*the area of the Triangle*/Point x1=list[stack[j]]-List[stack[i]]; Point X2=list[stack[k]]-List[stack[i]]; DoubleS=fabs (X1^X2)/2; MAXR=max (MAXR, (a*b*c)/(4*s)); } }}} printf ("%.2lf\n", maxr+0.5); }    return 0;}

Maple Trees (minimum cover circle)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.