首页 > 代码库 > hdu 3932 Groundhog Build Home

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): 2647    Accepted Submission(s): 1074


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 110 101000 50 40 01 00 11 1
 

 

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

 

Source
2011 Multi-University Training Contest 10 - Host by HRBEU
 

 

Recommend
We have carefully selected several similar problems for you:  3935 3934 3936 3931 3933 
题意:
  要求到给定n个点的最大距离最小的点,且点限定在给定矩形内,对应数学模型最小点覆盖。

首先考虑覆盖三个点的情况,有两种情况:

①:三个点都在圆上,则该圆是三角形的外接圆

②:两个点在圆上,第三个点在圆内,且在圆上的两个点之间的线段一定是直径

如果是多个圆,就不停地迭代。

有一点重要的是外接圆的求法,盗图说明:

技术分享

一溜证明来自zjk大神

#include<cstdio>#include<cstdlib>#include<ctime>#include<cmath>#include<algorithm>#define pf(x) ((x)*(x)) using namespace std;const int N=1e5+1;const double eps=1e-7;struct node{    double x,y;    void input(){scanf("%lf%lf",&x,&y);}}p[N],c;int n,X,Y;double r;double get_dis(const node &a,const node &b){    return sqrt(pf(a.x-b.x)+pf(a.y-b.y));}node get_focus(const node &a,const node &b,const node &c){    node t;    double c1=(a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)/2.0;    double c2=(c.x*c.x-b.x*b.x+c.y*c.y-b.y*b.y)/2.0;    t.x=(c1*(c.y-b.y)-c2*(a.y-b.y))/((a.x-b.x)*(c.y-b.y)-(c.x-b.x)*(a.y-b.y));    t.y=(c1*(c.x-b.x)-c2*(a.x-b.x))/((a.y-b.y)*(c.x-b.x)-(c.y-b.y)*(a.x-b.x));    return t;}void work(){    random_shuffle(p+1,p+n+1);    c=p[1];r=0;    for(int i=2;i<=n;i++){        if(get_dis(p[i],c)+eps>r){            c=p[i];r=0;            for(int j=1;j<i;j++){                if(get_dis(p[j],c)+eps>r){                    c.x=(p[i].x+p[j].x)/2;                    c.y=(p[i].y+p[j].y)/2;                    r=get_dis(c,p[j]);                    for(int k=1;k<j;k++){                        if(get_dis(p[k],c)+eps>r){                            c=get_focus(p[i],p[j],p[k]);                            r=get_dis(c,p[k]);                        }                    }                }            }        }    }    printf("(%.1lf,%.1lf).\n%.1lf\n",c.x,c.y,r);}int main(){    srand(time(0));    while(scanf("%d%d%d",&X,&Y,&n)==3){        for(int i=1;i<=n;i++) p[i].input();        work();    }     return 0;}

 

 

hdu 3932 Groundhog Build Home