最小圆覆盖

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath> using namespace std;
const double eps=0.00000001;
struct point {
double x,y;
}p[110]; struct circle{
point cent;
double rad;
}cir;
int n; double TriangleArea(point t1,point t2,point t3){
point p1,p2;
p1.x=t1.x-t3.x; p1.y=t1.y-t3.y;
p2.x=t2.x-t3.x; p2.y=t2.y-t3.y;
return fabs(p1.x*p2.y-p2.x*p1.y)/2;
} double dist(point p1,point p2){
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
} void TriangleCircle(point ta,point tb,point tc){
double a=dist(ta,tb);
double b=dist(tb,tc);
double c=dist(tc,ta);
cir.rad=(a*b*c)/TriangleArea(ta,tb,tc)/4;
double xa=ta.x; double ya=ta.y;
double xb=tb.x; double yb=tb.y;
double xc=tc.x; double yc=tc.y;
double c1=(xa*xa+ya*ya-xb*xb-yb*yb)/2;
double c2=(xa*xa+ya*ya-xc*xc-yc*yc)/2;
cir.cent.x=(c1*(ya-yc)-c2*(ya-yb))/((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb));
cir.cent.y=(c1*(xa-xc)-c2*(xa-xb))/((ya-yb)*(xa-xc)-(ya-yc)*(xa-xb));
} void slove(){
random_shuffle(p,p+n);
cir.cent=p[0]; cir.rad=0;
for(int i=1;i<n;i++){
if(dist(p[i],cir.cent)-eps>cir.rad ){
cir.cent=p[i]; cir.rad=0;
for(int j=0;j<i;j++){
if(dist(p[j],cir.cent)-eps>cir.rad ){
cir.cent.x=(p[j].x+p[i].x)/2;
cir.cent.y=(p[i].y+p[j].y)/2;
cir.rad=dist(p[j],p[i])/2;
for(int k=0;k<j;k++){
if(dist(p[k],cir.cent)-eps>cir.rad ){
TriangleCircle(p[i],p[j],p[k]);
}
}
}
}
}
}
} int main(){
while(scanf("%d",&n)!=EOF){
if(n==0) break;
for(int i=0;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
slove();
printf("%0.2f %0.2f %0.2f\n",cir.cent.x,cir.cent.y,cir.rad);
}
return 0;
}

  

ZOJ 1450的更多相关文章

  1. zoj 1450 Minimal Circle 最小覆盖圆

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

  2. HDU 3007 Buried memory & ZOJ 1450 Minimal Circle

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

  3. ZOJ 1450 Minimal Circle 最小圆覆盖

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

  4. ACM计算几何题目推荐

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

  5. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  6. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  7. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  8. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  9. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

随机推荐

  1. P2532 [AHOI2012]树屋阶梯 卡特兰数

    这个题是一个卡特兰数的裸题,为什么呢?因为可以通过划分来导出递推式从而判断是卡特兰数,然后直接上公式就行了.卡特兰数的公式见链接. https://www.luogu.org/problemnew/s ...

  2. 最新昆石VOS2009/VOS3000手机号段导入文件(手机归属地)

    使用2017年4月最新版手机号段归属地制作,支持所有版本的VOS 共360569条记录,兼容所有版本的昆石VOS,包括VOS2009.vos3000.vos5000 导入比较简单.下载后解压到桌面在V ...

  3. 洛谷 P2986 [USACO10MAR]Great Cow Gat…(树形dp+容斥原理)

    P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat… 题目描述 Bessie is planning the annual Great Cow Gathering for c ...

  4. 【K8s】Kubernetes架构理解

    抽空学习了一下Kubernetes,感觉和大数据领域内集群的资源管理.任务调度等有异曲同工之处,简单总结一下备忘. [概念] Kubernetes是一个工业级的容器编排平台,单词有点长,常用K8s代称 ...

  5. springboot+webmagic实现java爬虫jdbc及mysql

    前段时间需要爬取网页上的信息,自己对于爬虫没有任何了解,就了解了一下webmagic,写了个简单的爬虫. 一.首先介绍一下webmagic: webmagic采用完全模块化的设计,功能覆盖整个爬虫的生 ...

  6. iOS开发之判断手机号和邮箱 正则表达式

    #pragma mark --判断手机号合法性 + (BOOL)checkPhone:(NSString *)phoneNumber { NSString *regex = @"^((13[ ...

  7. ACM_Exponentiation

    Exponentiation Time Limit: 2000/1000ms (Java/Others) Problem Description: Problems involving the com ...

  8. 6月10遇到的bug

    3.遇到的BUG        1.@Service(version = "1.0.0", interfaceClass = TransactionItemService.clas ...

  9. shiro英语

    Security Manager安全管理人员 Tutorial 辅导的 transient 短暂的 Cipher 密码 Memory 记忆 Access 访问Handy Hint 方便提示separa ...

  10. jquery对象与DOM对象的转化(简化版):

    1:DOM对象 var apple = document.getElementById('apple'); 2:jquery对象 var _apple = $('#apple'); 3:DOM对象=& ...