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
 
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+;
const double eps=1e-;
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+,p+n+);
c=p[];r=;
for(int i=;i<=n;i++){
if(get_dis(p[i],c)+eps>r){
c=p[i];r=;
for(int j=;j<i;j++){
if(get_dis(p[j],c)+eps>r){
c.x=(p[i].x+p[j].x)/;
c.y=(p[i].y+p[j].y)/;
r=get_dis(c,p[j]);
for(int k=;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());
while(scanf("%d%d%d",&X,&Y,&n)==){
for(int i=;i<=n;i++) p[i].input();
work();
}
return ;
}
 

hdu 3932 Groundhog Build Home的更多相关文章

  1. hdu 3932 Groundhog Build Home——模拟退火

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932 注意平均值与最远的点距离为0的情况.所以初值设成-1,这样 id 就不会乱.不过设成0也可以.注意判 ...

  2. hdu 3932 Groundhog Build Home —— 模拟退火

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3932 找一个位置使距离最远的点的距离最小: 上模拟退火: 每次向距离最远的点移动,注意判断一下距离最远的点 ...

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

    和刚才那道是一模一样 不过求的是最小的,只要稍微修改一下就可以了~ //#pragma comment(linker, "/STACK:16777216") //for c++ C ...

  4. hdu 2215 & hdu 3932(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. Groundhog Build Home - HDU - 3932(模拟退火)

    题意 给定一个矩形内的\(n\)个点,在矩形中找一个点,离其他点的最大距离最小. 题解 模拟退火. 这个题需要\(x\)和\(y\)坐标随机动的时候多随机几次.否则就WA了.另外由于随机多次,如果温度 ...

  6. HDU 3932

    http://acm.hdu.edu.cn/showproblem.php?pid=3932 一定范围的平面上给一些点,求到这些点的最大距离最小,和上一题的题意正好相反,稍微改一下就可以 这个问题又叫 ...

  7. HDU 3932 模拟退火

    HDU3932 题目大意:给定一堆点,找到一个点的位置使这个点到所有点中的最大距离最小 简单的模拟退火即可 #include <iostream> #include <cstdio& ...

  8. 【2017 Multi-University Training Contest - Team 7 && hdu 6121】Build a tree

    [链接]点击打开链接 [题意] 询问n个点的完全k叉树,所有子树节点个数的异或总和为多少. [题解] 考虑如下的一棵k=3叉树,假设这棵树恰好有n个节点. 因为满的k叉树,第i层的节点个数为k^(i- ...

  9. HDU 6121 Build a tree(找规律+模拟)

    Build a tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)To ...

随机推荐

  1. 【CF732D】Exams(线性扫描,贪心,二分)

    题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复习a[i]天才能通过(可以不连续的复习得到a[i]),问最早什么时候可以把所有课程都通过,如果不能 ...

  2. DataSet用法一:添加代码创建的表DataTable,设置主键外键,读取及修改DataSet表中数据

    原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  3. 转 Python执行系统命令的方法

    传送门 Python执行系统命令的方法 http://www.linux-field.com/?p=15 Python中执行系统命令常见方法有两种: 两者均需 import os (1) os.sys ...

  4. unix网络编程第2章

    time_wait状态  可靠地实现tcp全双工连接的终止; (假设客户端先关闭).服务端再关闭,服务端将发送fin ,客户端此时进入time_wait状态.客户端接收到fin.将回一个ack.如果这 ...

  5. 二、 java中的变量与数据类型及类型转换

    标识符:凡是可以自己命名的地方都叫标识符,如:类名.方法名.接口名... 1.标识符命名的规则: 由26个英文字母大小写,0-9,_或$组成,不遵守会报错. 不可以用数字开头. 不能使用关键字和保留字 ...

  6. 矢量图和Word:EPS,PDF,EMF和SVG

    1.EMF和Word 在学校的时候,我思考过一个问题,论文中的插图如何保证清晰度.关键之一就是使用矢量图.参考知乎问题:如何在论文中画出漂亮的插图?.常见的矢量图包括:EPS,EMF和SVG.SVG适 ...

  7. 对农行金e顺k令的一些猜测

    手上有一个未激活的农行金e顺k令 开机后要求输入12位的激活码,随机输入多次,均告失败 花了点时间猜想k令的工作模式: 已知: k令无法联网,出厂后除了输入激活码的机会外,无法获取任何信息 k令内部有 ...

  8. Codeforces Gym 100431A Achromatic Number 欧拉回路

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  9. 某考试 T1 Hello my friend

    Discription

  10. Druid连接池工具类

    package cn.zmh.PingCe; import com.alibaba.druid.pool.DruidDataSourceFactory; import javax.sql.DataSo ...