最小圆覆盖

#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. [python基础] Flasky-表单WTForms支持的html字段和内建函数

    WTForms 支持的HTML 标准字段如表4-1 所示.表4-1 WTForms支持的HTML标准字段字段类型              说 明StringField           文本字段T ...

  2. Your configuration specifies to merge with the ref 'refs/heads/v.autoCheckProduct.20190325' from the remote, but no such ref was fetched.

    问题: 创建新的分支,当我们执行git pull,出现如下错误 解决办法: 1.切换到主分支(或者被依赖的分支,也就是你从哪个分支上拉取新的分支),博主这里是master分支 2.执行以下两个命令 3 ...

  3. SQLServer2008 去除换行符

    declare @str varchar(8000)set @str='SQL语句' select replace(@str,char(10),'')

  4. collectionView必须点击两次才跳转

    今天遇到一个很奇怪的现象:collectionView必须点击两次才能跳转.具体看代码: -(void)collectionView:(UICollectionView *)collectionVie ...

  5. ThinkPHP5中的助手函数

    load_trait:快速导入Traits,PHP5.5以上无需调用 /** * 快速导入Traits PHP5.5以上无需调用 * @param string    $class trait库 *  ...

  6. 在 Laravel 应用中使用 pjax 进行页面加速

    说明# PHPHub 使用 pjax 来加速网页的加载, 这篇文章是在开发完此功能后做的笔记. 什么是 Pjax# .--. / \ ## a a ( '._) |'-- | _.\___/_ ___ ...

  7. layui 下拉框取值

    layui.use('form', function () { var form = layui.form; form.on('select(Status)', function (data) { c ...

  8. ubuntu18.0安装RabbitMQ

    RabbitMQ是一个消息队列,用于实现应用程序的异步和解耦.生产者将生产消息传送到队列,消费中从队列中拿取消息并处理.生产者不用关心是谁来消费,消费者不用关系是谁在生产消息,从而达到解耦的目的.本文 ...

  9. KVM之virsh管理虚拟机内存

    调整内存 virsh setmem 命令帮助: [root@ubuntu ~]# virsh setmem --help NAME setmem - change memory allocation ...

  10. BZOJ 3012: [Usaco2012 Dec]First! 字典树 + tarjan

    Code: #include<bits/stdc++.h> #define maxn 1000003 using namespace std; char str[maxn],strtot[ ...