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

最新文章

  1. RecyclerView的使用(四)
  2. response.sendRedirect()与request.getRequestDispatcher().forward()区别
  3. Linux_使用Linux之安装jdk 7
  4. Java基础(7):二维数组初始化时需要注意的问题
  5. 【BZOJ1251】序列终结者
  6. WinAPI——UnhookWindowsHookEx - 卸掉钩子
  7. 使用NSTimer实现倒计时-备
  8. stagefright框架(四)-Video Buffer传输流程
  9. K - K.Bro Sorting
  10. PHP 5 数据类型
  11. java程序运行结果
  12. java集合框架之Collections
  13. mciSendString 多线程播放多首音乐 &amp; 注意事项
  14. springboot的创建
  15. 2019-03-25-day018-面向对象
  16. 01python简介
  17. 前端学习 -- Css -- 盒子模式
  18. name是个特殊的变量名吗
  19. ASP正则匹配方法
  20. java IO切割流合并流

热门文章

  1. php validator classes
  2. node总结--回调函数阻塞和非阻塞代码实例
  3. [LeetCode] Jump Game 数组控制
  4. PatentTips - MPLS Network System
  5. Keep-Alive 长连接(转载)
  6. LeetCode OJ--Triangle **
  7. win10 升级导致找不到SQL Server配置管理器
  8. js -“=”“==”和“===”的区别
  9. 图片点击放大并可点击旋转插件(1)-jquery.artZoom.js
  10. HDU 1045 Fire Net 状压暴力