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 ...
随机推荐
- CF459E Pashmak and Graph (Dag dp)
传送门 解题思路 \(dag\)上\(dp\),首先要按照边权排序,然后图都不用建直接\(dp\)就行了.注意边权相等的要一起处理,具体来讲就是要开一个辅助数组\(g[i]\),来避免同层转移. 代码 ...
- MyBatis的查询
MyBatis的查询 在上一个MyBatis的核心API中介绍了SqlSessionFactoryBuilder.SqlSessionFactory以及SqlSession是什么,它们都有什么作用,本 ...
- 7_1.springboot2.x启动配置原理_1.创建SpringApplication对象
环境准备 springboot2.1.9.idea2019. pom.xml 解析 几个重要的事件回调机制 配置在META-INF/spring.factories ApplicationContex ...
- python Six 模块
Six模块用于python2和python3的兼容 import six 官网链接:https://six.readthedocs.io/
- 如何将存储在MongoDB数据库中的数据导出到Excel中?
将MongoDB数据库中的数据导出到Excel中,只需以下几个步骤: (1)首先,打开MongoDB安装目录下的bin文件夹,(C:\Program Files (x86)\MongoDB\Serve ...
- 使用subprocessm模块管理进程
subprocess被用来替换一些老的模块和函数,如:os.system.os.spawn*.os.popen*.popen2.*.commands.*. subprocess的目的就是启动一个新的进 ...
- 威胁预警|首现新型RDPMiner挖矿蠕虫 受害主机易被添加恶意账户
近日,阿里云安全发现一种新型挖矿蠕虫RDPMiner,通过爆破Windows Server 3389端口RDP服务的方式进行挖矿木马传播,致使用户CPU占用率暴涨,机器卡顿,更被创建名为Default ...
- csp-s模拟65Simple,Walk, Travel,棋盘题解
题面:https://www.cnblogs.com/Juve/articles/11639923.html simple: 考试时只想到的暴力exgcd判断 考虑n,m互质的情况: 我们枚举y,对于 ...
- 前端-form表单与CSS
目录 form表单 表单属性 label标签 input标签 select 下拉框标签 textarea多行文本 提交 Flask 结合form表单 初探 CSS介绍以及基本选择器 基本选择器 组合选 ...
- Nginx 和 Gunicorn 部署 Django项目
目录 Nginx 和 Gunicorn 部署 Django项目 配置Nginx 安装配置Gunicorn 通过命令行直接启动 Gunicorn 与 uwsgi 的区别,用哪个好呢 Gunicorn u ...