链接

普通的暴力复杂度达到O(n^4),对于这题肯定是不行的。

解法:随机增量算法

参考http://www.2cto.com/kf/201208/149602.html

algorithm:
A、令Ci表示为前i个点的最小覆盖圆。当加入新点pi时如果pi不在Ci-1里那么pi必定在Ci的边界上。
B、再从新考虑这样一个问题,Ci为前i个点最小覆盖圆且p在Ci的的边界上!同理加入新点pi时如果p
i不在Ci-1里那么pi必定在Ci的边界上。这时我们就包含了两个点在这个最小圆的边界上。
C、再从新考虑这样一个问题,Ci为前i个点最小覆盖圆且有两个确定点再边界上!此时先让
O(N)的方法能够判定出最小圆。
------------------------------------------------------------------------------------
analysis:
现在来分析为什么是线性的。
C是线性的这是显然的。
B<-C的过程中。考虑pi 他在园内的概率为 (i-1)/i 。在圆外的概率为 1/i 所以加入pi的期望复杂度为:(1-i)/i*O(1) +(1/i)*O(i) {前者在园内那么不进入C,只用了O(1)。后者进入C用了O(i)的时间}这样分析出来,复杂度实际上仍旧
是线性的。
A<-B的过程中。考虑方法相同,这样A<-B仍旧是线性。于是难以置信的最小圆覆盖的复杂度变成了线性的。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 505
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x=,double y = ):x(x),y(y){}
}p[N];
typedef point pointt ;
pointt operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
point circumcenter(point a, point b, point c)
{ //返回三角形的外心
point ret;
double a1 = b.x-a.x,b1 = b.y-a.y,c1 = (a1*a1+b1*b1)/;
double a2 = c.x-a.x,b2 = c.y-a.y,c2 = (a2*a2+b2*b2)/;
double d = a1*b2-a2*b1;
ret.x=a.x+(c1*b2-c2*b1)/d;
ret.y=a.y+(a1*c2-a2*c1)/d;
return ret;
}
void min_cover_circle(point p[],int n,point &c,double &r)
{
random_shuffle(p,p+n);
c = p[],r = ;
int i,j,g;
for(i = ; i < n ;i++)
{
if(dcmp(dis(p[i]-c)-r)>)
{
c = p[i];
r = ;
for(j = ; j < i ; j++)
{
if(dcmp(dis(p[j]-c)-r)>)
{
c = point((p[i].x+p[j].x)/,(p[i].y+p[j].y)/);
r = dis(p[j]-c);
for(g = ; g < j; g++)
if(dcmp(dis(p[g]-c)-r)>)
{
c = circumcenter(p[i],p[j],p[g]);
r = dis(p[i]-c);
}
}
}
}
}
}
int main()
{
int n,i;
while(scanf("%d",&n)&&n)
{
for(i = ; i < n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
point c;
double r;
min_cover_circle(p,n,c,r);
printf("%.2f %.2f %.2f\n",c.x,c.y,r);
}
return ;
}
 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 505
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x=,double y = ):x(x),y(y){}
}p[N];
typedef point pointt ;
pointt operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
point circumcenter(point a, point b, point c)
{ //返回三角形的外心
point ret;
double a1 = b.x-a.x,b1 = b.y-a.y,c1 = (a1*a1+b1*b1)/;
double a2 = c.x-a.x,b2 = c.y-a.y,c2 = (a2*a2+b2*b2)/;
double d = a1*b2-a2*b1;
ret.x=a.x+(c1*b2-c2*b1)/d;
ret.y=a.y+(a1*c2-a2*c1)/d;
return ret;
}
void min_cover_circle(point p[],int n,point &c,double &r)
{
random_shuffle(p,p+n);
c = p[],r = ;
int i,j,g;
for(i = ; i < n ;i++)
{
if(dcmp(dis(p[i]-c)-r)>)
{
c = p[i];
r = ;
for(j = ; j < i ; j++)
{
if(dcmp(dis(p[j]-c)-r)>)
{
c = point((p[i].x+p[j].x)/,(p[i].y+p[j].y)/);
r = dis(p[j]-c);
for(g = ; g < j; g++)
if(dcmp(dis(p[g]-c)-r)>)
{
c = circumcenter(p[i],p[j],p[g]);
r = dis(p[i]-c);
}
}
}
}
}
}
int main()
{
int n,i;
while(scanf("%d",&n)&&n)
{
for(i = ; i < n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
point c;
double r;
min_cover_circle(p,n,c,r);
printf("%.2f %.2f %.2f\n",c.x,c.y,r);
}
return ;
}

hdu3007Buried memory(最小圆覆盖)的更多相关文章

  1. [日常摸鱼]HDU3007Buried memory-最小圆覆盖

    最小圆覆盖裸题 我求外接圆的方法比较奇怪-不过还是过掉了 #include<cstdio> #include<cmath> #include<cstdlib> #i ...

  2. 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1573   ...

  3. Bzoj 1336&1337 Alien最小圆覆盖

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special Judge Submit: 1473  ...

  4. bzoj1336: [Balkan2002]Alien最小圆覆盖

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1336 1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 ...

  5. 2018.07.04 BZOJ 2823: AHOI2012信号塔(最小圆覆盖)

    2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MB Description 在野外训练中,为了确保每位参加集训的成员安全,实时的掌握 ...

  6. 2018.07.04 BZOJ1336&&1337: Balkan2002Alien最小圆覆盖

    1336: [Balkan2002]Alien最小圆覆盖 1337: 最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special Judge Des ...

  7. bzoj 1336 最小圆覆盖

    最小圆覆盖 问题:给定平面上的一个点集,求半径最小的一个圆,使得点集中的点都在其内部或上面. 随机增量算法: 定义:点集A的最小圆覆盖是Circle(A) 定理:如果Circle(A)=C1,且a不被 ...

  8. [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】

    题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...

  9. [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】

    题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...

随机推荐

  1. listview实现点击条目上的箭头展开隐藏菜单。

    效果如下图,当点击listview中的小三角时,显示出下面布局,再点隐藏, 点击其他条目的三角时,上一个展开的条目隐藏的同时展开当前条目. 思路是在item布局中放入展开菜单的布局,并设置状态为隐藏, ...

  2. android使用其他应用打开文件

    根据文件的MIME类型来判断,手机中有哪些应用可以打开这个文件,然后把应用在弹窗列表中显示 /** * 打开文件 * * @param file */ public static void openF ...

  3. C语言的数组名和对数组名取地址

    http://blog.csdn.net/zdcsky123/article/details/6517811 相信不少的C语言初学者都知道,数组名相当于指针,指向数组的首地址,而函数名相当于函数指针, ...

  4. (摘至)程序员老鸟写sql语句的经验之谈

    做管理系统的,无论是bs结构的还是cs结构的,都不可避免的涉及到数据库表结构的设计,sql语句的编写等.因此在开发系统的时候,表结构设计是否合理,sql语句是否标准,写出的sql性能是否优化往往会成为 ...

  5. Optimal Milking 分类: 图论 POJ 最短路 查找 2015-08-10 10:38 3人阅读 评论(0) 收藏

    Optimal Milking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 13968 Accepted: 5044 Case ...

  6. Speed Limit 分类: POJ 2015-06-09 17:47 9人阅读 评论(0) 收藏

    Speed Limit Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17967   Accepted: 12596 Des ...

  7. 异步I/O

    http://blog.csdn.net/gotosola/article/details/7412409 Linux2.6异步I/O AIO的基本思想:  允许进程发起很多I/O操作,而不用阻塞或等 ...

  8. SqlSever基础 select cast 将一个int类型数据转换为char

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  9. 去处HTML标签

    JavaScript去处HTML标签 function removeHTMLTag(str) { str = str.replace(/<\/?[^>]*>/g, ''); //去除 ...

  10. 【leetcode❤python】350. Intersection of Two Arrays II

    #-*- coding: UTF-8 -*- class Solution(object):    def intersect(self, nums1, nums2):                ...