题目链接

最小圆覆盖

并不知道为什么是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. PropTypes使用

    PropTypes防止后期代码传参数错误,所以加一个校验, 代码: import React, {Component,PropTypes} from 'react'; import {View, Te ...

  2. 002-linux命令-文件和目录、查看文件内容-文件和目录、查看文件内容

    一.文件和目录 cd /home :进入‘/home’目录 cd .. 返回上一级目录 cd ../..返回上两级目录 cd 进入个人的主目录 cd ~user1进入个人的主目录 cd - 返回上次所 ...

  3. Redis入门到高可用(七)——Hash

    一.结构 Mapmap结构: filed 不能相同,value可以相同. 二.重要指令 ♦️ HSET  ♦️ HGET  ♦️ HDEL ♦️ Hlen  ♦️ HEXISTS ♦️HGETALL  ...

  4. strlen函数细节

    strlen所作的仅仅是一个计数器的工作,它从内存的某个位置(可以是字符串开头,中间某个位置,甚至是某个不确定的内存区域)开始扫描,直到碰到第一个字符串结束符'\0'为止,然后返回计数器值. 原型: ...

  5. Object类(API文档)

    java.lang Class Object java.lang.Object public class Object Class Object is the root of the class hi ...

  6. 高并发负载均衡——nginx与lvs

    一.企业级web项目架构 一.企业级web项目架构图 二.架构分析 客户端通过企业防火墙发送请求 在App服务器如tomcat接收客户端请求前,面对高并发大数据量访问的企业架构,会通过加入负载均衡主备 ...

  7. Python重要网址

    极客学院视频:http://www.jikexueyuan.com/path/python/ 知乎爬虫:https://www.zhihu.com/collection/129856874?page= ...

  8. [LeetCode] 596. Classes More Than 5 Students_Easy tag:SQL

    There is a table courses with columns: student and class Please list out all classes which have more ...

  9. 2019年UI和UX设计趋势:大概是最全的汇总了!

    朋友们,很快,2018就要跟我们说

  10. MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)

    MVC 默认 Request 方式为 Post. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三&qu ...