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 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?
Input the 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.
Output Minimal required radius of the circle ring I has to choose. The precision should be 10^-2.
Sample Input
2 1 0-1) 0 0
Sample Output
1.50
Author ZJT
Computational geometry, minimum circle coverage, here I'm using the random increment method, which is expected to be O (n). First point as the center, find the first not in the circle or the point of the circle, with it as the center, to find the second not in the circle or the point of the circle, the midpoint of the two points for the center, the distance is the diameter, to find a third not on the circle or in the circle of the point, the three points formed by the circumcenter of the Triangle as the center The last thing you get is the smallest circle that covers all points.
Minimum circle Overlay--random increment method, expected to be O (n)
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <math.h>
using namespace Std;
Const double EPS = 1e-8;
struct POINT
{
Double x, y;
}P[105];
Double Dist (Point A, point B)
{
return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));//Calculation distance
}
Back to Circumcenter
Point CrossPoint (Point p0, point P1, point p2)
{
Point ret;
Double A1 = p1.x-p0.x, B1 = p1.y-p0.y, C1 = (A1 * A1 + B1 * B1)/2;
Double A2 = p2.x-p0.x, b2 = p2.y-p0.y, C2 = (A2 * a2 + b2 * b2)/2;
Double d = A1 * b2-a2* B1;
Ret.x = p0.x + (C1 * B2-C2 * B1)/D;
Ret.y = p0.y + (A1 * C2-A2 * C1)/D;
return ret;
}
Double min_cover_circle (int n)
{
Random_shuffle (p, p + N);//Scramble Order
Point C = p[0];
Double r = 0;
for (int i = 1; i < n; ++i)
{
if (Dist (p[i], C) > R)//First point
{
c = P[i];
R = 0;
for (int j = 0; J < i; ++j)
{
if (Dist (p[j], C) > R)
{
c.x = (p[i].x + p[j].x)/2;
C.y = (p[i].y + p[j].y)/2;
R=dist (P[j], c);
for (int k = 0; k < J; ++k)
{
if (Dist (p[k], C) > R)
{
c = CrossPoint (P[i], p[j], p[k]);
R = Dist (c, p[k]);
}
}
}
}
}
}
return R;
}
int main ()
{
int n;
while (~SCANF ("%d", &n) && N)
{
for (int i = 0; i < n; ++i)
{
scanf ("%lf%lf", &p[i].x, &P[I].Y);
}
if (n = = 1)
printf ("0.50\n");//The tree itself also has a radius, and the calculation is used in the center, so the output is also added to the radius of the tree
Else
{
Double r = min_cover_circle (n);
printf ("%.2lf\n", R + 0.50);
}
}
return 0;
}