基本小圆覆盖模板题

#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. Spark底层原理简化版

    目录 Spark SQL/DF的执行过程 集群运行部分 Aggregation Join Shuffle Tungsten 内存管理机制 缓存敏感计算(Cacheaware computation) ...

  2. Mock实现模拟python的对象

    Mock库的应用 Mock在Python3.3之前是第三方库,需要安装 pip install Mock :导入 import mock Mock在Python3.3之后是Python标准库,导入方式 ...

  3. Django day08 多表操作 (四) 一对多, 多对多连续跨表查询

    一对多 # 基于双下划线的一对多查询 # 查询出版社为上海出版社的所有图书 # ret = Publish.objects.filter(name='上海出版社').values('book__nam ...

  4. NPM 国内镜像使用方法

    npm官方站点: http://www.npmjs.org/ 本文使用国内镜像地址: http://www.cnpmjs.org/ 搜索镜像:https://npm.taobao.org/ 具体方法: ...

  5. MSP430之data type

  6. dubbo之泛化引用

    使用泛化调用 泛化接口调用方式主要用于客户端没有 API 接口及模型类元的情况,参数及返回值中的所有 POJO 均用 Map 表示,通常用于框架集成,比如:实现一个通用的服务测试框架,可通过 Gene ...

  7. [实战经验][SQL Sever 2008 (R)解决方法累积

    SQL Sever 2008 (R)的安装图解及配置 http://www.soft6.com/v9/2009/jcsj_1030/115821.html 产品密钥,选择“输入产品密钥”,输入:PTT ...

  8. (转) OpenLayers3基础教程——OL3 介绍control

    http://blog.csdn.net/gisshixisheng/article/details/46761535 概述: 本文讲述的是Ol3中的control的介绍和应用. OL2和OL3 co ...

  9. (转) OpenLayers3基础教程——加载资源

    概述: 本节讲述如何在Ol3中加载wms图层并显示到地图中. Ol3下载: 你可以在OL官网去下载,下载地址为http://openlayers.org/download/,也可以去我的百度云盘下载, ...

  10. js 请求单个文件 并验证扩展名

    function suffix(file_name) { var three=file_name.split("."); ]; return last; } $('#btnSear ...