hud3007 Buried memory
最小圆覆盖
并不知道为什么是O(n)的,而且要随机化点的顺序
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define Clear(a,b) memset(a,b,sizeof(a))
#define inout(x) printf("%d",(x))
#define douin(x) scanf("%lf",&x)
#define strin(x) scanf("%s",(x))
#define LLin(x) scanf("%lld",&x)
#define op operator
#define CSC main
typedef unsigned long long ULL;
typedef const int cint;
typedef long long LL;
using namespace std;
const double eps=1e-;
double f(const long double &a){return a*a;}
void inin(int &ret)
{
ret=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=;ch=getchar();}
while(ch>=''&&ch<='')ret*=,ret+=ch-'',ch=getchar();
ret=f?-ret:ret;
}
struct xl
{
double x,y;
xl(double x=.,double y=.):x(x),y(y){}
xl op + (const xl &rhs){return xl(x+rhs.x,y+rhs.y);}
xl op / (const double &rhs){return xl(x/rhs,y/rhs);}
void in(){douin(x),douin(y);}
};
double dis(const xl &a,const xl &b)
{
return sqrt(f(a.x-b.x)+f(a.y-b.y));
}
xl di[];
int n;
xl outoftriangle(const xl &A,const xl &B,const xl &C)
{
double bx=B.x-A.x,by=B.y-A.y;
double cx=C.x-A.x,cy=C.y-A.y;
double area=*(bx*cy-by*cx);
double x=(cy*(f(bx)+f(by))-by*(f(cx)+f(cy)))/area+A.x;
double y=(bx*(f(cx)+f(cy))-cx*(f(bx)+f(by)))/area+A.y;
return xl(x,y);
}
xl solve(double &r)
{
xl ret;
random_shuffle(di+,di+n+);
ret=di[];r=.;
re(i,,n)if(dis(di[i],ret)>r+eps)
{
ret=di[i],r=.;
re(j,,i-)if(dis(di[j],ret)>r+eps)
{
ret=(di[i]+di[j])/.;
r=dis(di[j],ret);
re(k,,j-)if(dis(di[k],ret)>r+eps)
{
ret=outoftriangle(di[i],di[j],di[k]);
r=dis(di[i],ret);
}
}
}
return ret;
}
int main()
{
while(scanf("%d",&n)&&n)
{
re(i,,n)di[i].in();
double r;
xl c=solve(r);
printf("%.2f %.2f %.2f\n",c.x,c.y,r);
}
return ;
}
hud3007 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 ...
- 【HDOJ】3007 Buried memory
1. 题目描述有n个点,求能覆盖这n个点的半径最小的圆的圆心及半径. 2. 基本思路算法模板http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066定义Di表示 ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- [hdu-3007]Buried memory 最小覆盖圆
大致题意: 平面上有n个点,求一个最小的圆覆盖住所有点 最小覆盖圆裸题 学习了一波最小覆盖圆算法 #include<cstdio> #include<iostream> #in ...
- HDU - 3007 Buried memory
传送门 最小圆覆盖模板. //Achen #include<algorithm> #include<iostream> #include<cstring> #inc ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- 最小圆覆盖(随机增量法&模拟退火法)
http://acm.hdu.edu.cn/showproblem.php?pid=3007 相关题型连接: http://acm.hdu.edu.cn/showproblem.php?pid=393 ...
- HDU 3007 模拟退火算法
Buried memory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- react native获取屏幕的宽度和高度
var Dimensions = require('Dimensions'); var {width,height} = Dimensions.get("window");//第一 ...
- element
<el-table-column label="地址" prop="address"> <template slot-scope=" ...
- bcolz的新操作
1.直接修改 eg:把data.bcolz文件中A列为0的数据填充为1000. data = bcolz.open("data.bcolz", "a") #以& ...
- (转)RBAC权限表的设计
RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地说,一个用户拥有若干角色,每一个角色拥有若干权限.这样,就构造成“用户-角色- ...
- mysql相关SQL
1.mysql分组获取最新数据 sql> select max(column_name) from table group by column_name having count(*) orde ...
- kfrobotaidlog查找
======查看最新的大于6的数量========== select c.questionid from (select a.questionid, b.clientQuestion from sim ...
- 前端MD5加密【单向加密】
密码存储的方式: 密码该如何存储呢?按照安全性由低到高,有这样几种选择: 1.密码名文直接存储在系统中 2.密码经过对称加密后再存储 3.密码经过非对称加密后再存储 步骤: 1.用户端:用户提交用户名 ...
- [Git/GitHub] Tutorial 1. Git download and commit first project
1. Install at https://git-scm.com/downloads 2. Set up your name and email $ git config --global user ...
- CentOS6.5 安装Kafka集群
1.安装zookeeper 参考文档:http://www.cnblogs.com/hunttown/p/5452138.html 2.下载:https://www.apache.org/dyn/cl ...
- vue2.0--请求数据
vue中用vue-reouse请求来的数据,会被封装一层,如下图res: