最小圆覆盖

#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. php处理类

    Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Python, PHP, OCaml等等诸多编程语言的支 ...

  2. DCOM 找不到 office word 的解决方法

    1. 在运行里面  输入     comexp.msc -32  2.在“DCOM配置”中,为IIS账号配置操作Word(其他Office对象也一样)的权限. 具体操作:“组件服务(Component ...

  3. POJ 2553 Tarjan

    题意:如果v点能到的所有点反过来又能到v点,则v点是sink点,排序后输出所有的sink点. 思路:Tarjan缩点,输出所有出度为0的连通块内的点. PS:一定要记得把数组清零!!!!!!!否则自己 ...

  4. Struts/Hibernate/Spring源码下载

    Struts: https://olex.openlogic.com/packages/struts Hibernate: https://olex.openlogic.com/packages/hi ...

  5. 使用 CSS 追踪用户

    原文地址:Crooked Style Sheets 作者:jbtronics 除了使用 JS 追踪用户,现在有人提出了还可以使用 CSS 进行网页追踪和分析,译者认为,这种方式更为 优雅,更为 简洁, ...

  6. CDC之Synchronizers

    1 Scenarios Two scenarios for passing signals across CDC boundaries: 1) sometimes it's not necessary ...

  7. 使用OpenCV画折线图

    使用OpenCV画直方图是一件轻松的事情,画折线图就没有那么Easy了,还是使用一个库吧: GraphUtils 源代码添加入工程 原文链接:http://www.360doc.com/content ...

  8. Java_Reflect反射

    类是对象,类是java.lang.Class类的实例对象.There is a class named Class class Foo{} public class ClassDemo{ public ...

  9. es6-set-map数据结构

    Set的用法 set的key一定是字符串 { let list=new Set(); list.add(5);//向set中增加值要用add() list.add(6); console.log('s ...

  10. 【剑指Offer】54、字符流中第一个不重复的字符

      题目描述:   请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g".当从该字 ...