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. cocos2d-x的坐标和节点层级

  2. LAMP架构应用实战—Apache服务介绍与安装01

    LAMP架构应用实战—Apache服务介绍与安装01   一:Apache是什么 Apache是Apache基金会开发的一个高性能.功能强大.安全可靠.灵活的开放源码的WEB服务软件 二:Apache ...

  3. 剑指offer-反转链表15

    题目描述 输入一个链表,反转链表后,输出新链表的表头. class Solution: # 返回ListNode def ReverseList(self, pHead): # write code ...

  4. 基于语音转录的ted演讲推荐

    论文地址:https://arxiv.org/abs/1809.05350v1 二.  实现 我们从Kaggle[6]中获取了TED演讲数据集,其中包括2400个TED演讲的数据,包括标题.演讲者.标 ...

  5. JQuery Ajax执行过程AOP拦截

    JQuery Ajax过程AOP:用于在Ajax请求发送过程中执行必备操作,比如加载数据访问令牌. $.ajaxSetup({ type: "POST", error: funct ...

  6. POJ 2161 Chandelier(动态规划)

    Description Lamps-O-Matic company assembles very large chandeliers. A chandelier consists of multipl ...

  7. STL应用——hdu1412(set)

    set函数的应用 超级水题 #include <iostream> #include <cstdio> #include <algorithm> #include ...

  8. scrapy学习-爬取天天基金网基金列表

    目录 描述 环境描述 步骤记录 创建scrapy项目 设置在pycharm下运行scrapy项目 分析如何获取数据 编写代码 step 1:设置item step 2:编写spider step 3: ...

  9. Top K 算法详解

    http://xingyunbaijunwei.blog.163.com/blog/static/7653806720111149318357/ 问题描述         百度面试题:        ...

  10. .Net 面试总结

    今天去面试了一家公司,做电子商务类的网站的,公司的老板应该比较有能量,可以同时拿下若干项目,技术负责人给提了几个问题: 记不清顺序了 .net 构析函数的作用 泛型的主要作用及应用方面 结构与类的区别 ...