基本小圆覆盖模板题

#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. c++ string 解析ip

    比如输入是192.168.80.12-15,解析成192.168.80.12.192.168.80.13.192.168.80.14.192.168.80.15. #include <iostr ...

  2. nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter

    转自:https://blog.csdn.net/licheng989/article/details/28929411 在Bean中有代码 public abstract Axe getAxe(); ...

  3. Candies(差分约束系统)

    http://poj.org/problem?id=3159 思路:用O(V+ElogV)的Dijkstra算法求1到n的最短路.即用优先队列优化Dijkstra算法. #include <st ...

  4. Django day13 form组件, 渲染错误信息, 全局钩子

    一:from组件 二:渲染错误信息 三:全局钩子

  5. POJ 1523 Tarjan求割点

    SPF Description Consider the two networks shown below. Assuming that data moves around these network ...

  6. C - Arrival of the General

    Problem description A Ministry for Defense sent a general to inspect the Super Secret Military Squad ...

  7. 2.Dubbo开源分布式服务框架(JAVA RPC)

    1. Dubbo介绍 Dubbox是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能RPC(即远程调用)实现服务的输出和输入功能, 可以和Spring框架无集成.Dubbo是一款高性能 ...

  8. Css小动画

    html页面: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF ...

  9. 读书笔记「Python编程:从入门到实践」_7.用户输入和while循环

    7.1 函数input()的工作原理 函数input() 让程序暂停运行,等待用户输入一些文本.获取用户输入后,Python将其存储在一个变量中,以方便你使用. message = input(&qu ...

  10. 【C++】四种排序算法的时间比较

    四种排序算法的时间比较 [注]clock函数对输入(用户输入)元素N排序的计时 #include<iostream> #include<time.h> using namesp ...