题目链接

最小圆覆盖

并不知道为什么是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的更多相关文章

  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(计算几何の最小圆覆盖,模版题)

    Problem Description Each person had do something foolish along with his or her growth.But,when he or ...

  3. 【HDOJ】3007 Buried memory

    1. 题目描述有n个点,求能覆盖这n个点的半径最小的圆的圆心及半径. 2. 基本思路算法模板http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066定义Di表示 ...

  4. HDU 3007 Buried memory & ZOJ 1450 Minimal Circle

    题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...

  5. [hdu-3007]Buried memory 最小覆盖圆

    大致题意: 平面上有n个点,求一个最小的圆覆盖住所有点 最小覆盖圆裸题 学习了一波最小覆盖圆算法 #include<cstdio> #include<iostream> #in ...

  6. HDU - 3007 Buried memory

    传送门 最小圆覆盖模板. //Achen #include<algorithm> #include<iostream> #include<cstring> #inc ...

  7. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  8. 最小圆覆盖(随机增量法&模拟退火法)

    http://acm.hdu.edu.cn/showproblem.php?pid=3007 相关题型连接: http://acm.hdu.edu.cn/showproblem.php?pid=393 ...

  9. HDU 3007 模拟退火算法

    Buried memory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. HBase单机模式安装

    第一部分 安装前准备 1.安装hadoop 今天刚刚学了hbase的一点基础,准备安装Hbase实际操练一下.因为安装hbase的前提条件是已经成功安装了hadoop,而且hadoop的版本要和hba ...

  2. nginx --反向代理配置文件

    配置文件如下图   server { listen 8080; server_name 0.0.0.0;//这里可以配置相应域名 root /www/facei; index index.html i ...

  3. ftp工具类

    package com.ytd.zjdlbb.service.zjdlbb; import java.io.File;import java.io.FileInputStream;import jav ...

  4. v-show 和 v-if 对 v-chart的影响

    借鉴:https://blog.csdn.net/xiaxiangyun/article/details/78909991 使用v-show控制tab切换 其中一个tab数据请求后显示第二个tab,第 ...

  5. 学习Shell(二)变量

    如何给shell脚本传入参数 1.执行“vi test.sh”创建一个新的shell脚本. vi test.sh 2.脚本test.sh的内容如下: #!/bin/sh name=$ echo &qu ...

  6. rpm: /root/anaconda3/lib/liblzma.so.5: version `XZ_5.1.2alpha' not found (required by /lib64/librpmio.so.3)

    报如上的错误,发现rpm相关的命令都不能够用. 1.搜到这篇文章,https://stackoverflow.com/questions/47633870/rpm-lib64-liblzma-so-5 ...

  7. inner join, left join, right join 和 full join

    inner join:理解为“有效连接”,两张表中都有的数据才会显示left join:理解为“有左显示”,比如on a.field=b.field,则显示a表中存在的全部数据及a.b中都有的数据,a ...

  8. [ErrorException] "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

    Mac上PHP更新到7.3,使用Composer报这个错误 解决办法: composer selfupdate

  9. network error:software caused connection abort

    使用Putty链接阿里云香港服务器报这个错误. vim /etc/ssh/sshd_config 找到如下配置 #ClientAliveInterval 540 #ClientAliveCountMa ...

  10. Mac 安装HTMLTestRunner模块

    1.下载HTMLTestRunner.py文件 下载地址http://tungwaiyip.info/software/HTMLTestRunner.html 将下载的文件放在lib下: /Libra ...