ZOJ1450 Minimal Circle
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的更多相关文章
- ZOJ1450 Minimal Circle 最小圆覆盖
ZOJ1450 给定N个点(N<=100)求最小的圆把这些点全部覆盖 考虑对于三角形,可以唯一的找到外接圆,而多边形又可以分解为三角形,所以对于多边形也可以找到唯一的最小覆盖圆. #includ ...
- zoj 1450 Minimal Circle 最小覆盖圆
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to fi ...
- ZOJ 1450 Minimal Circle 最小圆覆盖
套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- ZOJ1450 BZOJ1136 BZOJ1137 HDU3932[最小圆覆盖]
Minimal Circle Time Limit: 5 Seconds Memory Limit: 32768 KB You are to write a program to find ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- Bootstrap Thumbnail
Square Thumbnail with Image <!-- Square Thumbnail with Image --> <com.beardedhen.androidboo ...
- (译)Minimal Shader(最小的着色器)
(原文:https://en.wikibooks.org/wiki/Cg_Programming/Unity/Minimal_Shader) This tutorial covers the basi ...
- Centos 7 minimal install 无网络无ifconfig的解决
Centos7这个比较不厚道, minimal install下居然不带net-tools 先要连上网络 修改/etc/sysconfig/network-scripts/ifcfg-ens12312 ...
随机推荐
- 环境变量 - JDK
Linux 1. 备份并编辑配置文件 # cp /etc/profile /etc/profile.bak # vi /etc/profile 2. 设置JDK环境变量 export JAVA_HOM ...
- kindeditor 限制上传图片大小及宽高
进入:/kindeditor/plugins/image/image.js,替换其中的 self.plugin.imageDialog = function (options)方法,代码为: self ...
- weblogic中配置自定义filter和servlet
情景:最近公司产品要接入其它厂商的单点服务器,本来我是在Tomcat上进行测试,使用的是spring boot 的注解方式@webFilter和@webServlet注解写过滤器和servlet类,启 ...
- 基于规则的中文分词 - NLP中文篇
之前在其他博客文章有提到如何对英文进行分词,也说后续会增加解释我们中文是如何分词的,我们都知道英文或者其他国家或者地区一些语言文字是词与词之间有空格(分隔符),这样子分词处理起来其实是要相对容易很多, ...
- node gyp的问题
解决 binding.gyp not found (xxx/xxx/xxx) while trying to load binding.gyp 问题 在使用ccap图形验证码模块时遇到这个问题 Err ...
- 使用Microsoft EnterpriseLibrary(微软企业库)日志组件把系统日志写入数据库和xml文件
这里只是说明在项目中如何配置使用微软企业库的日志组件,对数据库方面的配置请参考其他资料. 1.在项目中添加Microsoft.Practices.EnterpriseLibrary.Data.dll. ...
- iOS-UIImageView播放动画
NSArray *gifArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"lanya1"],[UIImage imag ...
- ASP.NET MVC如何使用输出缓存
通过这篇文章你将学习到在MVC中如何使用输出缓存,业务逻辑我就不多介绍了,主要是Outputcache的基本使用.至于数据缓存还是等我的下一篇文章吧,一步一步来不急的. 输出缓存的使用方法是在Co ...
- Hibernate配置文件说明
<property name="hbm2ddl.auto">create</property> create - 启动Hibernate前先删除表,重新创建 ...
- ES索引
Elasticsearch索引别名.Filtered索引别名.Template 在使用elasticsearch的时候,经常会遇到需要淘汰掉历史数据的场景. 为了方便数据淘汰,并使得数据管理更加灵活, ...