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

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;
}
时间: 2024-10-17 02:25:38

hdu 3932 Groundhog Build Home的相关文章

HDU - 3932 Groundhog Build Home 模拟退火算法

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 b

hdu 3932 Groundhog Build Home —— 模拟退火

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932 找一个位置使距离最远的点的距离最小: 上模拟退火: 每次向距离最远的点移动,注意判断一下距离最远的点距离为0的情况. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<cstdlib&

HDU 3932 Groundhog Build Home 【基础模拟退火】

和刚才那道是一模一样 不过求的是最小的,只要稍微修改一下就可以了~ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream> #include <cstring> #include <cmath> #include <stack>

HDU 3932

http://acm.hdu.edu.cn/showproblem.php?pid=3932 一定范围的平面上给一些点,求到这些点的最大距离最小,和上一题的题意正好相反,稍微改一下就可以 这个问题又叫最小圆覆盖 #include <iostream> #include <cstdio> #include <cstring> #include <map> #include <ctime> #include <cmath> using n

平面点集的最小包围圆 hdu 3932

最小覆盖圆算法地址:http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066 平面点集的最小包围圆 1.           问题背景 考察固定在工作平台上的一直机械手,要捡起散落在不同位置的多个零件,并送到别的地方.那么,这只机械手的底座应该选在哪里呢?根据直觉,应该选在机械手需够着的那些位置的"中心".准确地讲,也就是包围这些点的那个最小圆的圆心----该位置的好处是,可使机械手的底座到它需要够着的那些点的最大距离最小化.于是可得如下问题:给

HDU 3932 模拟退火

HDU3932 题目大意:给定一堆点,找到一个点的位置使这个点到所有点中的最大距离最小 简单的模拟退火即可 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <ctime> 7 #include <algorithm> 8 9 using name

计算几何及其应用——解析几何

写在前面:刚学专业课的时候,记得有天突发奇想,心说高三数学的压轴题能不能写个程序跑出答案,这样岂不是解放了数万苦逼高三生的双手?但是当时也仅仅是停留在想法上面,因为高中的解析几何虽然步骤程序化,但是有时候需要灵巧的因式分解,感觉以目前的编程水平还是写不出来,但是了解到数学有一个分支——计算几何,专门利用计算机来进行几何计算的一门科学,并且还与计算机图形学.计算机视觉和图像处理.机器人.计算机辅助设计和制造等高深学科有着联系(摘自<计算几何与应用>导言),所以今天怀着激动的心情开始了这个专题的学

poj1379+POJ2420+hdu3932(最短距离+费马点+模拟淬火算法)

Run Away Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5632   Accepted: 1729 Description One of the traps we will encounter in the Pyramid is located in the Large Room. A lot of small holes are drilled into the floor. They look complet

覆盖点问题总结

1.最小的包围圆,将所有的点包围起来.(hdu 3932)最小覆盖圆算法地址:http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066 问题的背景提出:考察固定在工作平台上的一直机械手,要捡起散落在不同位置的多个零件,并送到别的地方.那么,这只机械手的底座应该选在哪里呢?根据直觉,应该选在机械手需够着的那些位置的"中心".准确地讲,也就是包围这些点的那个最小圆的圆心----该位置的好处是,可使机械手的底座到它需要够着的那些点的最大距离最小化.于是