hdu 3932 Groundhog Build Home (最小圆覆盖)

Groundhog Build Home

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2634    Accepted Submission(s): 1067


Problem Description
Groundhogs are good at digging holes, their home is a hole, usually a group of groundhogs will find a more suitable area for their activities and build their home at this area .xiaomi has grown up, can no longer live with its parents.so it needs to build its own home.xiaomi like to visit other family so much, at each visit it always start from the point of his own home.Xiaomi will visit all of the groundhogs' home in this area(it will chose the linear distance between two homes).To save energy,xiaomi would like you to help it find where its home built,so that the longest distance between xiaomi's home and the other groundhog's home is minimum.
 

Input
The input consists of many test cases,ending of eof.Each test case begins with a line containing three integers X, Y, N separated by space.The numbers satisfy conditions: 1 <= X,Y <=10000, 1 <= N<= 1000. Groundhogs acivity at a rectangular area ,and X, Y is the two side of this rectangle, The number N stands for the number of holes.Then exactly N lines follow, each containing two integer numbers xi and yi (0 <= xi <= X, 0 <= yi <= Y) indicating the coordinates of one home.
 

Output
Print exactly two lines for each test case.The first line is the coordinate of xiaomi's home which we help to find. The second line is he longest distance between xiaomi's home and the other groundhog's home.The output round to the nearest number with exactly one digit after the decimal point (0.05 rounds up to 0.1).
 

Sample Input
  
  
1000 50 1 10 10 1000 50 4 0 0 1 0 0 1 1 1
 

Sample Output
  
  
(10.0,10.0). 0.0 (0.5,0.5). 0.7
 

Source
 

Recommend
We have carefully selected several similar problems for you:   3935  3936  3931  3933  3930 
 

Statistic |  Submit |  Discuss | Note

题解:最小圆覆盖

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#define N 10005
#define eps 1e-7
using namespace std;
int n,m;
struct vector {
	double x,y;
	vector (double X=0,double Y=0){
		x=X,y=Y;
	}
}p[N],tmp;
double x,y,ans,r,pi=acos(-1.0);
typedef vector point;
vector operator -(vector a,vector b){
	return vector (a.x-b.x,a.y-b.y);
}
vector operator +(vector a,vector b){
	return vector (a.x+b.x,a.y+b.y);
}
vector operator *(vector a,double t){
	return vector (a.x*t,a.y*t);
}
vector operator /(vector a,double t){
	return vector (a.x/t,a.y/t);
}
bool operator <(vector a,vector b){
	return a.x<b.x||a.x==b.x&&a.y<b.y;
}
int dcmp(double x)
{
	if (fabs(x)<eps) return 0;
	return x<0?-1:1;
}
double len(vector a){
	return sqrt(a.x*a.x+a.y*a.y);
}
double cross(vector a,vector b)
{
	return a.x*b.y-a.y*b.x;
}
vector rotate(vector a,double rad)
{
	return vector (a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
point glt(point p,vector v,point q,vector w)
{
	vector u=p-q;
	double t=cross(w,u)/cross(v,w);
	return p+v*t;
}
point center(point a,point b,point c){
	point p=(a+b)/2; point q=(a+c)/2;
	vector v=rotate(b-a,pi/2); vector u=rotate(c-a,pi/2);
	if (dcmp(cross(v,u))==0) {
		if(dcmp(len(a-b)+len(b-c)-len(a-c))==0)
            return (a+c)/2;
        if(dcmp(len(a-c)+len(b-c)-len(a-b))==0)
            return (a+b)/2;
        if(dcmp(len(a-b)+len(a-c)-len(b-c))==0)
            return (b+c)/2;
	}
	return glt(p,v,q,u);
}
double mincc(point *p,int n,point &c)
{
	random_shuffle(p,p+n);
	c=p[0];
	double  r=0;
	int i,j,k;
	for (i=1;i<n;i++)
	if (dcmp(len(c-p[i])-r)>0){
		c=p[i],r=0;
		for (j=0;j<i;j++)
		if (dcmp(len(c-p[j])-r)>0){
			c=(p[i]+p[j])/2;
			r=len(c-p[i]);
			for (k=0;k<j;k++)
			if (dcmp(len(c-p[k])-r)>0){ 
			  c=center(p[i],p[j],p[k]);
			  r=len(c-p[i]);
			}
		}
	}
	return r;
}
int main()
{
	freopen("a.in","r",stdin);
	while (scanf("%lf%lf%d",&x,&y,&n)!=EOF) {
		for (int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
		r=mincc(p,n,tmp);
		printf("(%.1lf,%.1lf).\n",tmp.x,tmp.y);
		printf("%.1lf\n",r);
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值