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. 【NOIP2016练习】T2 旅行(树形DP,换根)

    题意:小C上周末和他可爱的同学小A一起去X湖玩. X湖景区一共有n个景点,这些景点由n-1条观光道连接着,从每个景点开始都可以通过观光道直接或间接地走到其他所有的景点.小C带着小A从1号景点开始游玩. ...

  2. 升级 GCC 支持C++11 或 configure: error: *** A compiler with support for C++11 language features is required.

    configure: error: *** A compiler with support for C++11 language features is required. 参考链接: (1)升级 G ...

  3. svn不是内部或外部命令?

    svn不是内部或外部命令? 我的系统是Win7, [计算机]-->右键[属性]-->[高级系统设置]-->[环境变量]-->[系统变量 (S)]-->[Path]--&g ...

  4. LeetCode OJ--Path Sum *

    https://oj.leetcode.com/problems/path-sum/ 树的深搜,求从根到叶子的路径. 记住深搜的样子 #include <iostream> using n ...

  5. Nginx日志参数、location匹配规则、设置密码

    1.三个参数 a)$http_referer:记录此次请求是从哪个链接访问过来的: 是直接访问,还是从其他网站跳转过来的. 例如:访问:http://www.etiantian.com/,其页面首页是 ...

  6. java常用组件

    一.Jpanel 1.面板:容器类组件 2.用途:与Layout配合使用,JFrame—>JPanel—>Layout 二.JTextField 1.文本框 2.JPasswordFiel ...

  7. 3.环境搭建-Hadoop(CDH)集群搭建

    目录 目录 实验环境 安装 Hadoop 配置文件 在另外两台虚拟机上搭建hadoop 启动hdfs集群 启动yarn集群 本文主要是在上节CentOS集群基础上搭建Hadoop集群. 实验环境 Ha ...

  8. 【翻译自mos文章】使用asmcmd命令在本地和远程 asm 实例之间 拷贝asm file的方法

    使用asmcmd命令在本地和远程 asm 实例之间 拷贝asm file的方法 參考原文: How to Copy asm files between remote ASM instances usi ...

  9. 【IE】IE对line-height 失效的的解决方案

    微软的IE9 + Extjs3.1 确实头疼.在使用了line-height:20px 的Tree的样式,可是一直没有生效, 以下给出3中解决方式: 方案1.加padding-top: <div ...

  10. background-attachment

      CreateTime--2017年9月28日10:58:58 Author:Marydon background-attachment 1.定义 定义背景图片随滚动轴的移动方式(设置背景图像是否固 ...