hdu 3007【最小圆覆盖-随机增量法模板】
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=505;
int n;
double r;
struct dian
{
double x,y;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a) const
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a) const
{
return dian(x-a.x,y-a.y);
}
dian operator * (const double &a) const
{
return dian(x*a,y*a);
}
dian operator / (const double &a) const
{
return dian(x/a,y/a);
}
}p[N],c;
double dis(dian a,dian b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
dian yx(dian a,dian b,dian c)
{
dian p=b-a,q=c-a;
double c1=(p.x*p.x+p.y*p.y)/2,c2=(q.x*q.x+q.y*q.y)/2,d=cj(p,q);
return a+dian(c1*q.y-c2*p.y,c2*p.x-c1*q.x)/d;
}
int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=1;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
random_shuffle(p+1,p+1+n);
c=p[1],r=0;
for(int i=2;i<=n;i++)
if(dis(p[i],c)-r>0)
{
c=p[i],r=0;
for(int j=1;j<i;j++)
if(dis(p[j],c)-r>0)
{
c=(p[i]+p[j])/2,r=dis(p[j],c);
for(int k=1;k<j;k++)
if(dis(p[k],c)-r>0)
c=yx(p[i],p[j],p[k]),r=dis(p[k],c);
}
}
printf("%.2f %.2f %.2f\n",c.x,c.y,r);
}
return 0;
}
hdu 3007【最小圆覆盖-随机增量法模板】的更多相关文章
- 【bzoj1336/1337/2823】[Balkan2002]Alien最小圆覆盖 随机增量法
题目描述 给出N个点,让你画一个最小的包含所有点的圆. 输入 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000. ...
- 【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法
[BZOJ1336][Balkan2002]Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=10000 ...
- BZOJ.2823.[AHOI2012]信号塔(最小圆覆盖 随机增量法)
BZOJ 洛谷 一个经典的随机增量法,具体可以看这里,只记一下大体流程. 一个定理:如果一个点\(p\)不在点集\(S\)的最小覆盖圆内,那么它一定在\(S\bigcup p\)的最小覆盖圆上. 所以 ...
- [BZOJ2823][BZOJ1336][BZOJ1337]最小圆覆盖(随机增量法)
算法介绍网上有很多,不解释了. 给出三点坐标求圆心方法:https://blog.csdn.net/liyuanbhu/article/details/52891868 记得先random_shuff ...
- 洛谷 P1742 最小圆覆盖 (随机增量)
题目链接:P1742 最小圆覆盖 题意 给出 N 个点,求最小的包含所有点的圆. 思路 随机增量 最小圆覆盖一般有两种做法:随机增量和模拟退火.随机增量的精确度更高,这里介绍随机增量的做法. 先将所有 ...
- HDU 3007 最小圆覆盖 计算几何
思路: 随机增量法 (好吧这数据范围并不用) //By SiriusRen #include <cmath> #include <cstdio> #include <al ...
- 最小圆覆盖(随机增量法&模拟退火法)
http://acm.hdu.edu.cn/showproblem.php?pid=3007 相关题型连接: http://acm.hdu.edu.cn/showproblem.php?pid=393 ...
- 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1573 ...
- [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】
题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...
随机推荐
- 16 个常用的yum 命令
1. yum [-y] install package_name2. yum remove package_name 卸载指定软件3. ...
- java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
新建Maven 项目的时候报错: java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet ...
- ntfs格式uefi启动u盘
http://www.laomaotao.org/softhelp/syjc/925.html http://www.laomaotao.org/softhelp/wtjd/989.html http ...
- js的基础(平民理解的执行上下文/调用堆栈/内存栈/值类型/引用类型)
与以前的切图比较,现在的前端开发对js的要求似乎越来越高,在开发中,我们不仅仅是要知道如何运用现有的框架(react/vue/ng), 而且我们对一些基础的知识的依赖越来越大. 现在我们就用平民的方法 ...
- 搭建网络svn实战
工作中的问题(7) 转自:http://blog.csdn.net/xiaoting451292510/article/details/8562570 经常性我们和朋友写一些程序,大家在不同的城市确有 ...
- maven 的编译插件的配置
原文: https://stackoverflow.com/questions/29258141/maven-compilation-error-use-source-7-or-higher-to-e ...
- vi和vim上查找字符串
方法/步骤 1 我们以samba的配置文件为例,搜索一个user的字符串. vim /etc/samba/smb.conf 打开smb.conf 2 命令模式下,输入/user "/&quo ...
- Deepin-安装laravel
首先获取到composer.phar wget https://getcomposer.org/download/1.6.3/composer.phar 下载以后移动到目标区域 sudo mv com ...
- 挖掘更合适的MVP模式的架构设计
关于MVP,关于android,不得不说这篇博客已经来的非常晚了,这篇博客早就想写了,一直都在偷懒,就不给自己这么久的偷懒找借口了.尽管这篇文章po出来的比較晚.可是我所接触的程序猿一些朋友之 ...
- 【iOS系列】-textView的非常规使用
[iOS系列]-textView的非常规使用 文本框坐标设置一点距离 //文本框,左边间距 textView.leftView = [[UIView alloc] initWithFrame:CGRe ...