ZOJ 1450
最小圆覆盖
#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的更多相关文章
- zoj 1450 Minimal Circle 最小覆盖圆
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to fi ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- ZOJ 1450 Minimal Circle 最小圆覆盖
套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
随机推荐
- bzoj 1034 [ ZJOI 2008 ] 泡泡堂BNB —— 贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1034 一开始想了个很麻烦的贪心做法,对于每个 a[i],找第一个大于它的 b 匹配…… 然后 ...
- HTML中的文本框textarea标签
转自:https://www.jb51.net/web/183411.html <textarea></textarea>用来创建一个可以输入多行的文本框,此标志对用于< ...
- ReverseEngineerCodeFirst 自定义模板
1.在你要生成的项目里面在根目录下面添加CodeTemplates文件夹,并在该文件夹下面创建子文件夹ReverseEngineerCodeFirst 2.在ReverseEngineerCodeFi ...
- 快速掌握C#7
1. out 变量(out variables) 以前我们使用out变量必须在使用前进行声明,C# 7.0 给我们提供了一种更简洁的语法 “使用时进行内联声明” .如下所示: var input = ...
- [转]rdlc报表中表达式的使用--switch和IIF范例
本文转自:http://hi.baidu.com/oypx1234/item/5b35dec4e03a3ad697445266 =Switch( Fields!MLWHLO.Value = " ...
- dom转换成jquery对象
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- Jenkins上Git ssh登陆配置
1. 首先登陆linux机器 2. 切换到jenkins用户 3. 生成ssh key ssh-keygen -t rsa -C 'amysu@acxiom.com' 4. 将生成的ssh ke ...
- WPF播放器
最近由于工作需要,需要做一个播放软件,在网上参考了很多例子,园子里有很多代码.其中最多的就是wpf自带的MediaElement控件,或者VLC视频播放器. 先附我自己查询资料的链接: MediaEm ...
- 溢出文本省略号的js实现
function ellipsis(element) { var limitWidth = element.clientWidth; var temp = element.cloneNode(true ...
- CentOS 7 中配置通过 daemon 模式启动的 Tomcat 8 服务
距离上次折腾已经有很长一段时间了... 不说这个,刚好有空闲,把这两天折腾的 Tomcat 8 的服务配置整理出来收录一下. 1.JDK安装 1)检查服务器是否预装了 openJdk,如果有就删除,在 ...