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 ...
随机推荐
- Java压缩技术(三) ZIP解压缩——Java原生实现
原文:http://snowolf.iteye.com/blog/642492 JavaEye的朋友跟我说:“你一口气把ZIP压缩和解压缩都写到一个帖子里,我看起来很累,不如分开好阅读”.ok,面向读 ...
- Django day14(一) cookie
一: Cookie 1. Cookie是什么?存储在客户端浏览器上的键值对 2. 原理: 是服务器产生,发给客户端浏览器,浏览器保存起来,下次发请求,会携带这个键值对到服务器 4. Cookie的覆 ...
- 练习2 及pl/sql
Rownum 如果不是对主键排序是不会变得 -查询没有学分的学生信息 --SELECT * FROM z_student zs WHERE zs.code NOT IN (SELECT DISTINC ...
- F - Micro-World(简单模拟)
Problem description You have a Petri dish with bacteria and you are preparing to dive into the harsh ...
- Centos7.5 在桌面创建AndroidStudio快捷方式
Centos7 在桌面创建AndroidStudio快捷方式 前言 最近安装了Centos7,打算将开发平台转移到Linux下,安装好AndroidStudio后,桌面没有快捷方式有些不习惯,随自己创 ...
- OpenCL C
OpenCL C OpenCL 简介 opencl C是ISO C99的一个扩展,主要区别如下: 去除了C99的一些特性,如:标准C99头文件,函数指针,递归,变长数组,和位域 增加了一些特性用于并 ...
- [Advanced Algorithm] - Inventory Update
题目 依照一个存着新进货物的二维数组,更新存着现有库存(在 arr1 中)的二维数组. 如果货物已存在则更新数量 . 如果没有对应货物则把其加入到数组中,更新最新的数量. 返回当前的库存数组,且按货物 ...
- webapi部署到IIS 404错误
环境:win2008r2+IIS 解决方案: 添加一个映射 可执行文件地址(根据系统决定64位可32位): C:\Windows\Microsoft.NET\Framework64\v4.0.3031 ...
- sqlserver where in 在 mysql
) tmp); 主句(select * from (从句 temp) sql的 where in 删除 要更改为 // in( select * from ((select idfrom twhe ...
- webpack学习(六)—webpack+react+es6(第3篇)
接上篇 : webpack学习(六)—webpack+react+es6(第2篇) 上篇其实是有问题的,问题在取服务器数据这块.this.props 表示那些一旦定义,就不再改变的特性,而 this. ...