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 growth.But,when he or she did this that time,they could not predict that this thing is a mistake and they will want this thing would rather not happened.

The world king Sconbin is not the exception.One day,Sconbin was sleeping,then swakened by one nightmare.It turned out that his love letters to Dufein were made public in his dream.These foolish letters might ruin his throne.Sconbin decided to destroy the letters
by the military exercises‘s opportunity.The missile is the best weapon.Considered the execution of the missile,Sconbin chose to use one missile with the minimum destruction.

Sconbin had writen N letters to Dufein, she buried these letters on different places.Sconbin got the places by difficult,he wants to know where is the best place launch the missile,and the smallest radius of the burst area. Let‘s help Sconbin to get the award.

Input

There are many test cases.Each case consists of a positive integer N(N<500,^V^,our great king might be a considerate lover) on a line followed by N lines giving the coordinates of N letters.Each coordinates have two numbers,x coordinate and y coordinate.N=0
is the end of the input file.

Output

For each case,there should be a single line in the output,containing three numbers,the first and second are x and y coordinates of the missile to launch,the third is the smallest radius the missile need to destroy all N letters.All output numbers are rounded
to the second digit after the decimal point.

Sample Input

3
1.00 1.00
2.00 2.00
3.00 3.00
0

Sample Output

2.00 2.00 1.41

Source

2009 Multi-University Training Contest 11 -
Host by HRBEU

/* ***********************************************
Author        :CKboss
Created Time  :2014年12月29日 星期一 15时15分46秒
File Name     :HDOJ3007.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 = 888;
const double eps=1e-8;

struct Point
{
	double x,y;
}pt[maxn];

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}; }

int n;

int dcmp(double x)
{
	if(fabs(x)<eps) return 0;
	if(x>eps) return 1;
	else return -1;
}

double Cross(Point A,Point B) { return A.x*B.y-A.y*B.x; }
double Dot(Point a,Point b) { return a.x*b.x+a.y*b.y; }
double Length(Point a) { return sqrt(Dot(a,a)); }

struct Circle
{
	Point c; double r;
};

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;
	Circle c;
	c.c=(Point){cx,cy};
	c.r=Length(p1-c.c);
	return c;
}

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 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 %.2lf %.2lf\n",c.c.x,c.c.y,c.r);
	}

    return 0;
}
时间: 2024-08-01 17:44:07

HDOJ 3007 Buried memory 增量法最小圆覆盖的相关文章

HDU 3007 Buried memory 最小圆覆盖

题目大意:没看.反正就是求最小圆覆盖. 思路:一个神奇的算法--随机增量法.可以证明,这个算法可以在O(n)的时间复杂度内求出最小圆覆盖.虽然好像能卡掉的样子,但是加上一句random_shuffle就卡不掉了. 具体的过程是这样的: 在全局记录一个圆,表示目前的最小圆覆盖.从头开始扫描.遇到第一个不在当前最小圆覆盖内的点的时候: 将这个点与当前最小圆覆盖的圆心为直径做一个圆,作为当前的最小圆覆盖.从头开始扫描.遇到第一个不在当前最小圆覆盖的点的时候: 将刚才的两个点和当前点做三角形,将这个三角

【HDOJ】3007 Buried memory

1. 题目描述有n个点,求能覆盖这n个点的半径最小的圆的圆心及半径. 2. 基本思路算法模板http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066定义Di表示相对于P[1]和P[i]组成的最小覆盖圆,如果P[2..i-1]都在这个圆内,那么当前的圆心和半径即为最优解.如果P[j]不在这个圆内,那么P[j]一定在新的最小覆盖圆的边界上即P[1].P[j].P[i]组成的圆.因为三点可以确定一个圆,因此只需要不断的找到不满足的P[j],进而更新最优解即可.其

hdu 3007 Buried memory 最远点对

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007 Each person had do something foolish along with his or her growth.But,when he or she did this that time,they could not predict that this thing is a mistake and they will want this thing would rather

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 t

【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

【bzoj1336/1337/2823】[Balkan2002]Alien最小圆覆盖 随机增量法

题目描述 给出N个点,让你画一个最小的包含所有点的圆. 输入 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0) 输出 输出圆的半径,及圆心的坐标 样例输入 6 8.0 9.0 4.0 7.5 1.0 2.0 5.1 8.7 9.0 2.0 4.5 1.0 样例输出 5.00 5.00 5.00 题解 随机增量法求最小圆覆盖裸题 求法:设初始圆为某空圆,先枚举第一个点,如果不在当前圆内,则令当前圆为这一个点的最小圆

【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法

[BZOJ1336][Balkan2002]Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0) Output 输出圆的半径,及圆心的坐标 Sample Input 6 8.0 9.0 4.0 7.5 1.0 2.0 5.1 8.7 9.0 2.0 4.5 1.0 Sample Output 5.00 5.00 5

BZOJ 1336 Balkan2002 Alien最小圆覆盖 随机增量法

题目大意:求最小圆覆盖 随机增量法裸题 注意多输出几位小数不然过不去= = #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define M 100100 #define EPS 1e-7 using namespace std; struct Point

BZOJ 1337 最小圆覆盖 随机增量法

题意:链接 方法:随机增量法 解析: 首先把所有点打乱. 然后枚举第一个点,如果不在当前的圆内则把它设为圆心. 再枚举第二个点,如果不在当前的圆内则把圆设为其与第一个点的距离为直径的圆. 再枚举第三个点,如果不在当前的圆内则把圆设为这三个点构成三角形的外接圆. 然后最后就是答案了. 别问我这为什么是对的- -! 复杂度期望O(n),我是信了. 代码: #include <cmath> #include <cstdio> #include <iomanip> #inclu