基本小圆覆盖模板题

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int X,Y; int n;
const double eps=0.00000001;
struct point{
double x,y;
}p[550]; struct Circle{
point cent;
double r;
}cir; double dist(point x, point y){
double a=x.x-y.x;
double b=x.y-y.y;
return sqrt(a*a+b*b);
} double triangleArea(point t1, point t2, point t3){
point p1,p2;
p1.x=t2.x-t1.x; p1.y=t2.y-t1.y;
p2.x=t3.x-t1.x; p2.y=t3.y-t1.y;
return fabs(p1.x*p2.y-p1.y*p2.x)/2;
} Circle triangleCircle(point t1, point t2, point t3){
Circle tmp;
double a=dist(t1,t2);
double b=dist(t2,t3);
double c=dist(t3,t1);
tmp.r=a*b*c/triangleArea(t1,t2,t3)/4;
double xa,ya,xb,yb,xc,yc;
double c1,c2;
xa=t1.x; ya= t1.y;
xb=t2.x; yb= t2.y;
xc=t3.x; yc= t3.y;
c1=(xa*xa+ya*ya-xb*xb-yb*yb)/2;
c2=(xa*xa+ya*ya-xc*xc-yc*yc)/2;
tmp.cent.x=(c1*(ya-yc)-c2*(ya-yb))/((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb));
tmp.cent.y=(c1*(xa-xc)-c2*(xa-xb))/((ya-yb)*(xa-xc)-(ya-yc)*(xa-xb));
return tmp;
} void slove(){
random_shuffle(p,p+n);
cir.cent=p[0];
cir.r=0;
for(int i=1;i<n;i++){
if(dist(cir.cent,p[i])>cir.r){
cir.cent=p[i]; cir.r=0;
for(int j=0;j<i;j++){
if(dist(cir.cent,p[j])>cir.r){
cir.cent.x=(p[i].x+p[j].x)/2;
cir.cent.y=(p[i].y+p[j].y)/2;
cir.r=dist(p[i],p[j])/2;
for(int k=0;k<j;k++){
if(dist(cir.cent,p[k])>cir.r){
cir=triangleCircle(p[i],p[j],p[k]);
}
}
}
}
}
}
} int main (){
while(scanf("%d",&n),n){
for(int i=0;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
slove();
printf("%0.2lf %0.2lf ",cir.cent.x,cir.cent.y);
printf("%0.2lf\n",cir.r);
}
return 0;
}

  

HDU 3007的更多相关文章

  1. hdu 3007 Buried memory 最远点对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007 Each person had do something foolish along with ...

  2. HDU 3007 Buried memory & ZOJ 1450 Minimal Circle

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

  3. 最小圆覆盖 hdu 3007

    今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...

  4. HDU 3007 模拟退火算法

    Buried memory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  5. HDU 3007 Buried memory(计算几何の最小圆覆盖,模版题)

    Problem Description Each person had do something foolish along with his or her growth.But,when he or ...

  6. hdu 3007【最小圆覆盖-随机增量法模板】

    #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> usin ...

  7. HDU 3007 最小圆覆盖 计算几何

    思路: 随机增量法 (好吧这数据范围并不用) //By SiriusRen #include <cmath> #include <cstdio> #include <al ...

  8. HDU - 3007 Buried memory

    传送门 最小圆覆盖模板. //Achen #include<algorithm> #include<iostream> #include<cstring> #inc ...

  9. ACM计算几何题目推荐

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

随机推荐

  1. Android网络连接监听

    接收系统网络服务的广播接收者 public class NetStateReceiver extends BroadcastReceiver { private Handler handler; pu ...

  2. 一个豆瓣 API 的反向代理配置,旨在解决豆瓣屏蔽小程序请求问题(豆瓣接口 403 问题)

    #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...

  3. 捣鼓TinyMCE粘贴图片并上传+Flask后台

    好久没有编程了,最近需要完成一个小功能,为了方便,需要粘贴图片后上传到后台.前台编辑器用tinymce(N年前用过,我也就知道这个编辑器而已.这次使用下来感觉文档更丰富了),后台我用的Flask.昨天 ...

  4. bzoj1231[Usaco2008 Nov]mixup2 混乱的奶牛(状压dp)

    1231: [Usaco2008 Nov]mixup2 混乱的奶牛 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1032  Solved: 588[ ...

  5. python 关于文件操作的一些理解

    在用python进行数据处理编程中,往往涉及到文件IO口读写,IO口的读写性能会极大的影响程序的运行时间.在进行文件写入时,一般会存在两种情况.第一种是数据到来马上进行数据写入,即来一条写一条,第二种 ...

  6. TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method 'configure'

    TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method 'configure ...

  7. PL/SQL实现JAVA中的split()方法的小例子

    众所周知,java中为String类提供了split()字符串分割的方法,所以很容易将字符串以指定的符号分割为一个字符串数组.但是在pl/sql中并没有提供像java中的split()方法,所以要想在 ...

  8. Laravel5.1学习笔记6 响应

    基本响应 附加头信息到响应 附加Cookie到响应 其他响应 View视图响应 JSON响应 File下载 重定向 重定向到命名路由 重定向到控制器Action 附带闪回Session数据重定向 响应 ...

  9. 团队作业-Beta版本发布

    这个作业属于哪个课程  <课程的链接>            这个作业要求在哪里 <作业要求的链接> 团队名称 Three cobblers 这个作业的目标 Beta版本发布报 ...

  10. Spark on Yarn集群搭建

    软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这五部机, 每部主机的用户名都为centos ...