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 ...
随机推荐
- Bootstrap FileInput.js + springmvc uploadFile
下载FileInput.js http://plugins.krajee.com/file-input/demo https://github.com/kartik-v/bo ...
- xkl的各种沙雕低错
13,特判判掉20分算不算? 12,linux用c++11编译: g++ -std=c++11 -o a a.cpp g++ a.cpp -std=c++11 -o a //g++ a.cpp -st ...
- nginx的配置:目的是使用nginx反向代理后,应用程序获取用户真实ip
一.了解nginx Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的.从2004年发布至今,凭借开源的力量,已经接近成熟与完善. Nginx功能丰富,可作为HT ...
- vs数据库连接问题
在swagger上测试时报错:数据库连接不上 原因:在项目中修改过connectionstring,但是每次编译时本地文件中并没有更新 修改: 修改配置文件属性:不复制 —> 始终复制
- Spring+SpringMVC+Mybatis搭建的网站的处理流程总结
最近学习了如何使用SSM框架搭建网站,以前没用过框架,第一次使用,总结一下自己对框架处理流程的理解
- QString组合、拆分。
1.组合字符常用arg()函数 QString test=QString("_haha_%1_hehe%2") .arg("ee").arg("aa& ...
- Git log和reflog
1.log log命令可以显示所有提交过的版本信息.显示信息如下: Administrator@USER-20171026MG MINGW64 ~/Desktop/lyf (master) $ gi ...
- 愚人节老板发话了,免费送书 + 免费入驻Java知识星球!!
愚人节快乐,今天的活动很重磅! 1.免费送5本重量级技术书籍,不骗人,小程序随机抽奖送出哦! 2.免费进星球,哈哈不可能,愚人节快乐!不过今天有重大优惠,见下文! 活动一:免费送出5本重量级书籍 赠书 ...
- spring:ApplicationContext的三个实现类
* ApplicationContest的三个常用实现类* ClassPathXmlApplicationContext:它可以加载类路径的配置文件,要求配置文件必须在类路径下,如果不在则加载不了* ...
- 等差数列+随机数——cf1114E
先确定上界 然后用查询随机位置的数,求gcd作为公差即可 /* 给定一个size为n的打乱的等差数列 两个询问 ? i 询问第i个数的值 > x 询问大于的值是否存在 可以在30次内问出最大值 ...