(Hdu step 7.1.5) Maple trees (minimum radius of convex hull for cover wheel)

Source: Internet
Author: User

Title:

Maple Trees
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 177 Accepted Submission (s): 63
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 make this problem more simple, consider all the trees is circles in a plat E. 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


Topic Analysis:

The radius of the minimum cover circle for the convex hull. In fact, after finding the convex hull, we can ask for the minimum cover circle.

This problem requires some of the following knowledge:

1, about obtuse triangle, assuming that C is the hypotenuse, then there must be a^2 + b^2 < c^2 proof.



2. The area of a triangle is obtained by the three vertices of the triangle.

The vertex coordinates of the known triangle A1A2A3 ai (xi, yi) (i = 1, 2, 3). The area of the triangle is:

S = ((x2-x1) * (y3-y1)-(x3-x1) * (Y2-Y1))/2;

A1A2A3 boundary form Counterclockwise loop when Take +, clockwise time to take-.

In addition, in the process of solving. It is not necessary to consider whether the input order of points is clockwise or counterclockwise, and the division is offset.


3.

Convex hull + Minimum circle Overlay enumeration randomly 3 points to find its minimum coverage circle (when obtuse triangle is not circumscribed circle, but with its longest edge as the diameter of the circle). When circumscribed circle, the RADIUS formula is r=abc/4s; (deduced for example the following: By the sine theorem, a/sina=b/sinb=c/sinc=2r, sina=a/(2R), triangular area formula s= (Bcsina)/2, so s= (ABC)/(4R), So r= (ABC)/(4S).


This question also needs to be noted:

1, after the use of Graham to find the smallest convex package. Try to keep the convex hull closed. i.e. P[n] = p[0].



The code is as follows:

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm>using namespace std; Const double EPSI = 1e-8;const double pi = ACOs ( -1.0); const int MAXN = 101;struct ppoint{//struct Try not to define it as a point, easy and Variable with the same name Double x;double y;  PPoint (Double _x = 0,double _y = 0): X (_x), Y (_y) {}ppoint operator-(const ppoint& OP2) Const{return ppoint (x-op2.x,y -OP2.Y);} Double operator^ (const ppoint &AMP;OP2) Const{return x*op2.y-y*op2.x;}; inline int sign (const double &x) {if (x > Epsi) {return 1;} if (x <-epsi) {return-1;} return 0;} Inline double sqr (const double &x) {return x*x;} Inline double mul (const ppoint& p0,const ppoint& p1,const ppoint& p2) {return (p1-p0) ^ (p2-p0);} Inline double dis2 (const ppoint &p0,const ppoint &p1) {return Sqr (p0.x-p1.x) + SQR (P0.Y-P1.Y);} inline double dis (const ppoint& p0,const ppoint& p1) {return sqrt (Dis2 (P0,P1));} int n; PPoint P[MAXN]; PPoint convex_hull_p0;inline bool convex_hull_cmp (const Ppoint& A,const ppoint& b) {return sign (Mul (convex_hull_p0,a,b) >0) | | (Sign (Mul (convex_hull_p0,a,b)) = = 0 && dis2 (convex_hull_p0,a) < Dis2 (convex_hull_p0,b));} int Convex_hull (ppoint* a,int n,ppoint* b) {int i;for (i = 1; i < n; ++i) {if (sign (a[i].x-a[0].x) < 0 | | (sign (a[i].x-a[0].x) = = 0 && sign (A[I].Y-A[0].Y) < 0)) {swap (a[i],a[0]);}} Convex_hull_p0 = a[0];//These two lines of code do not change sequentially. Otherwise it will Wasort (A,A+N,CONVEX_HULL_CMP), b[0] = a[0];b[1] = A[1];int newn = 2;for (i = 2; i < n; ++i) {while (Newn > 1 && Amp Sign (Mul (b[newn-1],b[newn-2],a[i)) >= 0) {newn--;} b[newn++] = A[i];} return newn;} /** * There is a triangle of three points to calculate the area of this triangle */double Crossprod (ppoint A, PPoint B, PPoint C) {return (b.x-a.x) * (C.Y-A.Y)-(B.Y-A.Y) * ( c.x-a.x);} int main () {while (scanf ("%d", &n)!=eof,n) {int i;for (i = 0; i < n; ++i) {scanf ("%lf%lf", &p[i].x,&p[i].y);} /** * The number of processing nodes is only 1, 2 of the situation */if (n = = 1) {printf ("0.50\n"); continue;} if (n = = 2) {printf ("%.2lf\n", Dis (p[0],p[1])/2 + 0.5); continue;} /** * When the node is >=3, the Graham algorithm is used to find the minimum convex hull */n = convex_hull (p,n,p);p [n] = p[0];//Remember to close the knot, or it may be wrong int j;int k;double MAXR = -1;//for The radius of the minimum cover circle double r;/** * Enumerates arbitrarily three points in the convex package. * Assuming that these three points form the largest radius of the circumscribed circle, * then this is the smallest cover circle */for (i = 0; i < n; ++i) {for (j = i+1; j < n; ++j) {for (k = j+1; K &L t;= N; ++K) {//Note that the K here is <= ndouble a = Dis (p[i],p[j]);d ouble b = dis (p[i],p[k]);d ouble c = Dis (p[j],p[k]);//Assuming that these three points form the obtuse triangle if (A*a+b*b < C*c | | A*a+c*c < B*B | | B*b+c*c < A*A) {r = max (A, B), c)/2;//then the radius is equal to half the longest side}else{//the assumption is Right triangle | | Acute triangle double s = fabs (Crossprod (P[i],p[j],p[k]))/2;//is calculated by Theorem 1 for area r = a*b*c/(4*s);//triangle Circumscribed Circle Formula}if (MaxR < R) {//assuming the maximum radius stored at the moment < current circumscribed circle radius maxr = r;//updates the maximum radius}}}}printf ("%.2lf\n", MAXR + 0.5);//The maximum radius of the minimum coverage circle of the output convex hull}return 0;}













Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

(Hdu step 7.1.5) Maple trees (minimum radius of convex hull for cover wheel)

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.