题目链接

最小圆覆盖

并不知道为什么是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. wordpress用Elementor拖拽生成酷炫页面

    很多朋友看到wordpress网站做得很高大上,想知道是怎么做到的,其实很简单,用Elementor就能拖拽生成酷炫页面,ytkah就直接上干货了. 1.安装Elementor,到wordpress后 ...

  2. wordpress去掉<link rel='dns-prefetch' href='//s.w.org' />

    我们在用wordpress建站时经常会看到<link rel='dns-prefetch' href='//s.w.org' />,应该是为了从s.w.org预获取表情和头像,目的是提高网 ...

  3. 20170915 shell

    1.什么是Shell 一种电脑程序与文本文件,利用Shell 可以进行系统管理,文件操作等. 2.认识bash 这个Shell 由于管理整个计算机硬件的其实是操作系统的内核(kernel),用户一般都 ...

  4. Pycharm快捷键大全(windows + Mac)

    Windows快捷键 1.编辑 Ctrl + Space    基本的代码完成(类.方法.属性) Ctrl + Alt + Space  快速导入任意类 Ctrl + Shift + Enter    ...

  5. MSDN、OEM、VOL、RETAIL密钥区别

    本文就介绍一下Windows的密钥的一些使用要点及注意事项,涉及到最常用的MSDN密钥.OEM密钥.VOL密钥和零售密钥激活问题,希望对大家有所帮助. 一.MSDN密钥 MSDN密钥是付费用户提前获得 ...

  6. wx鼠标拖动事件

    #coding:UTF- import wx app = wx.App() def dragEVT(event): if event.ButtonDown(): panel1.SetPosition( ...

  7. ABPIAbpSession

    AbpSession定义了几个关键属性: UserId:当前用户的Id或空(如果没有当前用户),如果调用需要授权的代码,它就不能为空. TenantId:当前租户的Id或空(如果没有当前租户:尚未登录 ...

  8. JAVA基础——集合——ArrayList

    ArrayList集合 ArrayList的一些方法(JDK1.8): 将指定的元素附加到列表的末尾,true:添加成功,false:添加失败: public boolean add(E e)    ...

  9. git flow 使用步骤

    Mac安装git-flow:brew install git-flow 克隆新代码:git clone git@gitlab.xxx.cn:abc/test.git 切换到远程的develop分支(很 ...

  10. fasttext学习笔记

    When to use FastText? The main principle behind fastText is that the morphological structure of a wo ...