HDU - 3007 Buried memory
最小圆覆盖模板。
//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
const int N=;
typedef long long LL;
typedef double db;
using namespace std;
const db eps=1e-;
int n; db r; template<typename T>void read(T &x) {
char ch=getchar(); x=; T f=;
while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
if(ch=='-') f=-,ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
} struct pt {
db x,y;
pt(){}
pt(db x,db y):x(x),y(y){}
}p[N],c; pt operator + (pt A,pt B) { return pt(A.x+B.x,A.y+B.y); }
pt operator - (pt A,pt B) { return pt(A.x-B.x,A.y-B.y); }
db dot(pt A,pt B) { return A.x*B.x+A.y*B.y; }
db length(pt A) { return sqrt(dot(A,A)); }
int dcmp(db x) { if(fabs(x)<eps) return ; return x>?:-; } pt circle_center(pt a,pt b,pt c) {
pt res;
db a1=b.x-a.x,a2=c.x-a.x;
db b1=b.y-a.y,b2=c.y-a.y;
db c1=(a1*a1+b1*b1)/2.0;
db c2=(a2*a2+b2*b2)/2.0;
db d=a1*b2-a2*b1;
res.x=a.x+(b2*c1-b1*c2)/d;
res.y=a.y+(a1*c2-a2*c1)/d;
return res;
} void min_circle_cover(pt p[],int n,pt &c,db &r) {
random_shuffle(p+,p+n+);
c=p[]; r=;
for(int i=;i<=n;i++) {
if(dcmp(length(p[i]-c)-r)>) {
c=p[i]; r=;
for(int j=;j<i;j++) {
if(dcmp(length(p[j]-c)-r)>) {
c.x=(p[i].x+p[j].x)/;
c.y=(p[i].y+p[j].y)/;
r=length(p[i]-c);
for(int k=;k<j;k++) {
if(dcmp(length(p[k]-c)-r)>) {
c=circle_center(p[i],p[j],p[k]);
r=length(p[k]-c);
}
}
}
}
}
}
} int main() {
srand();
for(;;) {
read(n);
if(!n) break;
for(int i=;i<=n;i++)
scanf("%lf %lf",&p[i].x,&p[i].y);
min_circle_cover(p,n,c,r);
printf("%.2lf %.2lf %.2lf\n",c.x,c.y,r);
}
return ;
}
HDU - 3007 Buried memory的更多相关文章
- hdu 3007 Buried memory 最远点对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007 Each person had do something foolish along with ...
- HDU 3007 Buried memory(计算几何の最小圆覆盖,模版题)
Problem Description Each person had do something foolish along with his or her growth.But,when he or ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- 【HDOJ】3007 Buried memory
1. 题目描述有n个点,求能覆盖这n个点的半径最小的圆的圆心及半径. 2. 基本思路算法模板http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066定义Di表示 ...
- HDU 3007 模拟退火算法
Buried memory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 【23.68%】【hdu 2871】Memory Control
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...
- 最小圆覆盖 hdu 3007
今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...
- hud3007 Buried memory
题目链接 最小圆覆盖 并不知道为什么是O(n)的,而且要随机化点的顺序 #include<algorithm> #include<iostream> #include<c ...
- [hdu-3007]Buried memory 最小覆盖圆
大致题意: 平面上有n个点,求一个最小的圆覆盖住所有点 最小覆盖圆裸题 学习了一波最小覆盖圆算法 #include<cstdio> #include<iostream> #in ...
随机推荐
- 阿里云Aliplayer高级功能介绍(一):视频截图
基本介绍 H5 Video是不提供截图的API的, 视频截图需要借助Canvas,通过Canvas提供的drawImage方法,把Video的当前画面渲染到画布上, 最终通过toDataURL方法可以 ...
- 巧用CSS3的calc()宽度计算做响应模式布局
今天浏览这个http://www.sitepoint.com站时,因为好奇看了下人家写的代码,结果发现了这行代码, 于是就研究了一下,calc()从字面我们可以把他理解为一个函数function.其实 ...
- kubernetes istio的快速安装和使用例子
安装 [root@master ~]# wget https://github.com/istio/istio/releases/download/1.1.5/istio-1.1.5-linux.ta ...
- 单层感知机_线性神经网络_BP神经网络
单层感知机 单层感知机基础总结很详细的博客 关于单层感知机的视频 最终y=t,说明经过训练预测值和真实值一致.下面图是sign函数 根据感知机规则实现的上述题目的代码 import numpy as ...
- Form-Item Slot 自定义label内容
<el-form-item> <span slot="label">体 重:</span> <el-input v-model=&qu ...
- cookie的设置与销毁
<?php /* 2个参数设置cookie cookie随着浏览器的关闭,就失效了 ); /* 下面我们让cookir多活一会 3个参数来设置cookie,第3个参数指的就是cookie的声明周 ...
- <a>标签的SEO优化细节
<a>标签的SEO优化细节 如果需要在新窗口中打开链接,我们使用的方法是在a上加上taget=“_blank”,但很多人不知道这是不符合w3c的规范的,在使用严格的DOCTYPE(xhtm ...
- (转)线程池 ExecutorService 详细介绍以及注意点区别
线程池 ExecutorService 相信java开发都用到,这里做个简单笔记 一 Java通过Executors提供四种线程池,分别为: newCachedThreadPool创建一个可缓存线程池 ...
- Pascal代码自动格式化
const WEnter=; key=; next_line:..WEnter]of string=(';','begin','else','then','repeat','do','var'); k ...
- 解决git每次输入密码,设置gitlab、github默认push的用户名和密码
git ssh key配置&解决git每次输入密码 欢迎加入qq群(IT-程序猿-技术交流群):757345416 在使用git时,每次pull/push都需要输入密码,有时大大降低了我们 ...