Hdu2215 (minimum coverage circle)

Source: Internet
Author: User
Maple trees

Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1578 accepted submission (s): 488


Problem descriptionthere are 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 are circles in a plate. the diameter of all the trees are 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 is 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 is number of trees in this data set N (1 <= n <= 100), it is followed by N coordinates of the trees. each coordinate is a pair of integers, and each integer is in [-1000,100 0], it means the position of a tree's center. each pair is separated by blank.
Zero at line for number of trees terminates the input for your program.

 

Outputminimal required radius of the circle ring I have to choose. The precision shocould be 10 ^-2.

 

Sample input21 0-1 00

 

Sample output1.50: Use a smallest circle to circle all vertices inside. points can be on the circle, with a radius of 0.50.
  1 #include<stdio.h>  2 #include<math.h>  3 #define PI acos(-1.0)  4 struct   TPoint  5 {  6     double x,y;  7 }a[1005],d;  8 double r;  9 double   distance(TPoint   p1,   TPoint   p2) 10 { 11     return (sqrt((p1.x-p2.x)*(p1.x -p2.x)+(p1.y-p2.y)*(p1.y-p2.y))); 12 } 13 double multiply(TPoint   p1,   TPoint   p2,   TPoint   p0) 14 { 15     return   ((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y)); 16 } 17 void MiniDiscWith2Point(TPoint   p,TPoint   q,int   n) 18 { 19     d.x=(p.x+q.x)/2.0; 20     d.y=(p.y+q.y)/2.0; 21     r=distance(p,q)/2; 22     int k; 23     double c1,c2,t1,t2,t3; 24     for(k=1; k<=n; k++) 25     { 26         if(distance(d,a[k])<=r) 27             continue; 28         if(multiply(p,q,a[k])!=0.0) 29         { 30             c1=(p.x*p.x+p.y*p.y-q.x*q.x-q.y*q.y)/2.0; 31             c2=(p.x*p.x+p.y*p.y-a[k].x*a[k].x-a[k].y*a[k].y)/2.0; 32  33             d.x=(c1*(p.y-a[k].y)-c2*(p.y-q.y))/((p.x-q.x)*(p.y-a[k].y)-(p.x-a[k].x)*(p.y-q.y)); 34             d.y=(c1*(p.x-a[k].x)-c2*(p.x-q.x))/((p.y-q.y)*(p.x-a[k].x)-(p.y-a[k].y)*(p.x-q.x)); 35             r=distance(d,a[k]); 36         } 37         else 38         { 39             t1=distance(p,q); 40             t2=distance(q,a[k]); 41             t3=distance(p,a[k]); 42             if(t1>=t2&&t1>=t3) 43             { 44                 d.x=(p.x+q.x)/2.0; 45                 d.y=(p.y+q.y)/2.0; 46                 r=distance(p,q)/2.0; 47             } 48             else if(t2>=t1&&t2>=t3) 49             { 50                 d.x=(a[k].x+q.x)/2.0; 51                 d.y=(a[k].y+q.y)/2.0; 52                 r=distance(a[k],q)/2.0; 53             } 54             else 55             { 56                 d.x=(a[k].x+p.x)/2.0; 57                 d.y=(a[k].y+p.y)/2.0; 58                 r=distance(a[k],p)/2.0; 59             } 60         } 61     } 62 } 63  64 void MiniDiscWithPoint(TPoint   pi,int   n) 65 { 66     d.x=(pi.x+a[1].x)/2.0; 67     d.y=(pi.y+a[1].y)/2.0; 68     r=distance(pi,a[1])/2.0; 69     int j; 70     for(j=2; j<=n; j++) 71     { 72         if(distance(d,a[j])<=r) 73             continue; 74         else 75         { 76             MiniDiscWith2Point(pi,a[j],j-1); 77         } 78     } 79 } 80 int main() 81 { 82     int i,n; 83     while(scanf("%d",&n)&&n) 84     { 85         for(i=1; i<=n; i++) 86             scanf("%lf %lf",&a[i].x,&a[i].y); 87         if(n==1) 88         { 89             printf("0.50\n"); 90             continue; 91         } 92  93         r=distance(a[1],a[2])/2.0; 94         d.x=(a[1].x+a[2].x)/2.0; 95         d.y=(a[1].y+a[2].y)/2.0; 96         for(i=3; i<=n; i++) 97         { 98             if(distance(d,a[i])<=r) 99                 continue;100             else101                 MiniDiscWithPoint(a[i],i-1);102         }103         printf("%.2lf\n",r+0.5);104     }105     return 0;106 }
View code

 

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.