HDOJ 2215 Maple trees 最小圆覆盖

增量法最小圆覆盖....

Maple trees

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1646    Accepted Submission(s): 510

Problem Description

There 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 ?

Input

The 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, 1000],
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.

Output

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

Sample Input

2
1 0
-1 0
0

Sample Output

1.50

Author

zjt

/* ***********************************************
Author        :CKboss
Created Time  :2014年12月29日 星期一 17时19分19秒
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);
	double 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(Length(p[i]-c.c)-c.r)>0)
		{
			c.c=p[i]; c.r=0;
			for(int j=0;j<i;j++)
			{
				if(dcmp(Length(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);
		printf("%.2lf\n",c.r+0.5);
	}

    return 0;
}
时间: 2024-10-23 18:14:14

HDOJ 2215 Maple trees 最小圆覆盖的相关文章

HDOJ 3007 Buried memory 增量法最小圆覆盖

增量法最小圆覆盖,简单模版 Buried memory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2541    Accepted Submission(s): 1365 Problem Description Each person had do something foolish along with his or her g

(hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)

称号: 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 Description There are a lot of trees in HDU. Kiki want to surround all the trees with the m

(hdu step 7.1.5)Maple trees(求凸包的最小覆盖圆的半径)

题目: 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 Description There are a lot of trees in HDU. Kiki want to surround all the trees with the m

【BZOJ-1336&amp;1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)

1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1573  Solved: 697[Submit][Status][Discuss] Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0) Outpu

Maple trees(最小覆盖圆)

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 are a lot of trees in HDU. Kiki want to surround all the trees with the minim

BZOJ1337: 最小圆覆盖

题目:求n个点的最小圆覆盖. 题解:最小圆覆盖,上模板.复杂度证明可以戳:这里 代码: 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #inclu

最小圆覆盖模板

//最小圆覆盖 //输入: 从下标0开始的点集_ps和大小_n //输出: 覆盖所有点的最小圆 //复杂度: O(n) //注意: 会对_ps进行随机处理操作,将会改变点集的内部顺序 Circle MinCoverCir(Point _ps[],int _n) { //随机处理,但是会改变传入的点集. random_shuffle(_ps, _ps+_n);//复杂度O(_n) Circle rec; rec.r = 0; rec.c = _ps[0]; for(int i=1;i<_n;i++

ZOJ 1450 Minimal Circle 最小圆覆盖

套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <cstring> #include <cmath> #include <stack> #include <queue> #include <

最小圆覆盖 hdu 3007

今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部包围, 可以在圆的边界上 下面是我的个人理解. 如果不对, 还请路过大牛指出 先找一个点, 让圆心等于这个点的坐标, 半径等于0, 显然这个对的, 接着找下一个点, 如果只有两个点的话, 那么最小的圆一定是以他们为直径做圆, 接着找第三个点, 如果第三个点在园内或者在边界上, 那么不用更新当前的最小