You are to write a program to find a circle which covers a set of points and has the minimal area. There will be no more than 100 points in one problem.

Input

The input contains several problems. The first line of each problem is a line containing only one integer N which indicates the number of points to be covered. The next N lines contain N points. Each point is represented by x and y coordinates separated by a space. After the last problem, there will be a line contains only a zero.

Output

For each input problem, you should give a one-line answer which contains three numbers separated by spaces. The first two numbers indicate the x and y coordinates of the result circle, and the third number is the radius of the circle. (use escape sequence %.2f)

Sample Input

2
0.0 0.0
3 0
5
0 0
0 1
1 0
1 1
2 2
0

Sample Output

1.50 0.00 1.50
1.00 1.00 1.41

数学问题 几何

最小圆覆盖,随机增量法

其实就是枚举两个点作为圆直径上的两点,发现有点在当前圆外时,就调整直径……

随机增量法求最小圆覆盖。

三重循环。

令ci为前i个点的覆盖圆,新加入一个点i+1时,若其在圆内,跳过,若其在圆外,修改圆心使i+1在圆c(i+1)上。

检查之前的点,令ci为前i个点的覆盖圆,且点j在圆周上,若第i+1个点无法被圆覆盖,修改圆心使点i+1和点j都在圆周上。

检查之前的点,令ci为前i个点的覆盖圆,且点j和点k在圆周上,若第i+1个点无法被圆覆盖,修改圆心使点i+1和点j、点k都在圆周上

这算法倒是还能理解,但是求外心的几何算法表示看不懂。这个技能还是等高二再解锁吧。

      ——高一时候的博主

↑什么解锁技能啊……现在一回顾,就是设外心坐标,根据外心到三个顶点的距离相等来暴力列方程,解出来个表达式就行……

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const double eps=1e-;
const int mxn=;
struct Point{
double x,y;
Point operator + (Point rhs){return (Point){x+rhs.x,y+rhs.y};}
Point operator - (Point rhs){return (Point){x-rhs.x,y-rhs.y};}
double cross(Point rhs){return x*rhs.y-y*rhs.x;}
friend double dist(Point a,Point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
}p[mxn],O;
int n;
double r;
void clc(Point p1,Point p2,Point p3){//计算三角形外心
double a=*(p2.x-p1.x);
double b=*(p2.y-p1.y);
double c=p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y;
double d=*(p3.x-p1.x);
double e=*(p3.y-p1.y);
double f=p3.x*p3.x+p3.y*p3.y-p1.x*p1.x-p1.y*p1.y;
O.y=(d*c-a*f)/(b*d-e*a);
O.x=(b*f-e*c)/(b*d-e*a);
r=dist(O,p1);
return;
}
int main(){
int i,j;
while(scanf("%d",&n) && n){
for(i=;i<=n;i++){scanf("%lf%lf",&p[i].x,&p[i].y);}
O=p[];r=;
for(int i=;i<=n;i++)
if(dist(O,p[i])>r+eps){
O=p[i];r=;
for(j=;j<i;j++){
if(dist(O,p[j])>r+eps){
O.x=(p[i].x+p[j].x)/;
O.y=(p[i].y+p[j].y)/;
r=dist(O,p[j]);
for(int k=;k<j;k++){
if(dist(O,p[k])>r+eps)
clc(p[i],p[j],p[k]);
}
}
}
}
printf("%.2f %.2f %.2f\n",O.x,O.y,r);
}
return ;
}

ZOJ1450 Minimal Circle的更多相关文章

  1. ZOJ1450 Minimal Circle 最小圆覆盖

    ZOJ1450 给定N个点(N<=100)求最小的圆把这些点全部覆盖 考虑对于三角形,可以唯一的找到外接圆,而多边形又可以分解为三角形,所以对于多边形也可以找到唯一的最小覆盖圆. #includ ...

  2. zoj 1450 Minimal Circle 最小覆盖圆

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to fi ...

  3. ZOJ 1450 Minimal Circle 最小圆覆盖

    套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...

  4. HDU 3007 Buried memory & ZOJ 1450 Minimal Circle

    题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...

  5. ZOJ1450 BZOJ1136 BZOJ1137 HDU3932[最小圆覆盖]

    Minimal Circle Time Limit: 5 Seconds      Memory Limit: 32768 KB You are to write a program to find ...

  6. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  7. Bootstrap Thumbnail

    Square Thumbnail with Image <!-- Square Thumbnail with Image --> <com.beardedhen.androidboo ...

  8. (译)Minimal Shader(最小的着色器)

    (原文:https://en.wikibooks.org/wiki/Cg_Programming/Unity/Minimal_Shader) This tutorial covers the basi ...

  9. Centos 7 minimal install 无网络无ifconfig的解决

    Centos7这个比较不厚道, minimal install下居然不带net-tools 先要连上网络 修改/etc/sysconfig/network-scripts/ifcfg-ens12312 ...

随机推荐

  1. 清除远程桌面连接记录和SQLSERVER 连接记录的办法

    1.清除远程桌面连接记录: 清除远程桌面访问痕迹.使用windows系统自带的“远程桌面协助”mstsc进行远程,如果连接的用户多了,会留下访问的痕迹.虽然能带来方便,但是如果对于公用电脑来说,这些访 ...

  2. 《剑指offer》题解

    有段时间准备找工作,囫囵吞枣地做了<剑指offer>提供的编程习题,下面是题解收集. 当初没写目录真是个坏习惯(-_-)||,自己写的东西都要到处找. 提交的源码可以在此repo中找到:h ...

  3. Hadoop入门案列,初学者Coder

    1.WordCount Job类: package com.simope.mr.wcFor; import org.apache.hadoop.conf.Configuration; import o ...

  4. iOS笔记058 - IOS之多线程

    IOS开发中多线程 主线程 一个iOS程序运行后,默认会开启1条线程,称为"主线程"或"UI线程" 作用 显示和刷新界面 处理UI事件(点击.滚动.拖拽等) 注 ...

  5. Qt 汽车仪表再次编写,Widget,仪表显示,绘制界面

    感谢某网友提供UI让我练练手,上目前的效果 还在晚上,代码等后面在贴出来,就是出来显摆一下

  6. C++学习005-循环

    C++在循环方面,感觉个C没有身边么区别 while循环 for循环 do while循环 其实 使用Goto也可以写个循环 编写环境vs2015 1. while循环 int main() { in ...

  7. Leetcode 3. Longest Substring Without Repeating Characters (Medium)

    Description Given a string, find the length of the longest substring without repeating characters. E ...

  8. truffle的调用nodeJs的问题

    Truffle3.0集成NodeJS并完全跑通(附详细实例,可能的错误) 升级到Truffle3.0 如果之前安装的是Truffle2.0版本,需要主动升级到Truffle3.0,两者的语法变化有点大 ...

  9. POJ 3565 Ants(最佳完美匹配)

    Description Young naturalist Bill studies ants in school. His ants feed on plant-louses that live on ...

  10. URAL 1936 Roshambo(求期望)

    Description Bootstrap: Wondering how it's played? Will: It's a game of deception. But your bet inclu ...