基本小圆覆盖模板题

#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. 在linux查看内存的大小

    用free -m查看的结果: # free -m          total    used    free     shared buffers     cached Mem:           ...

  2. PCB MongoDB 数据库 Collection集合导出与导入

    由于一直以来用微软可视化图形界面习惯了,而MongoDB是命令式操作,而用系统自带CMD操作不方便, 这里介绍一款CMD的替代品,大小100多M. Cmder工具下载  https://github. ...

  3. PCB 3D PCB 后续改进与扩展功能一些想法

    再次感受到WelGl实现3D效果的震撼, 一.目前功能: Gerber与钻孔 解析 并转为3D实景图,用户360度操控 二.后续改进扩展功能: 1.增加ODB++解析 2. 3D 尺寸标注(外形尺寸, ...

  4. input点击修改样式

    <input id="geren" type="button" value="个人奖励" style="BORDER-TOP ...

  5. Linux<小白>详细笔记

    目录   应放置的内容 /bin  系统有很多放置执行文件的目录,但是/bin目录比较特殊./bin放置的是在单用户维护模式下还能够被操作的命令.在/bin下面的命令可以被root与一般用户使用. / ...

  6. LeetCode Weekly Contest 28

    1. 551. Student Attendance Record I 2. 552. Student Attendance Record II hihocode原题,https://hihocode ...

  7. Windows7 win10 系统如何强制禁用驱动程序签名

    转载自奇兔 Win7 64位系统禁用驱动程序签名强制    Win7系统是比较稳定的一款系统,也是最多人在使用的一款系统.当我们在Win7系统中安装驱动程序的时候,对安装的驱动程序需要数字签名,否则驱 ...

  8. [2月1号] 努比亚全机型ROM贴 最全最新NubiaUI5.0 ROOT 极速体验

    前言 感谢在开发过程中mandfx和dgtl198312予以的帮助!本帖将整理所有Nubia手机的最新刷机包,还有少数机型未制作刷机包,需要的机油可以联系我制作recovery以及刷机包加群23722 ...

  9. PHP 数组基础知识

    php 数组基础知识function abc($a,$b,$c = 0){ echo $a,$b,$c;}abc(1,3); //调用方法 ////可变参数function def(){ $arr = ...

  10. 【JSP】上传图片到数据库中

    第一步:建立数据库 create table test_img(id number(4),name varchar(20),img long raw); 第二步:(NewImg.html) <h ...