链接

普通的暴力复杂度达到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仍旧是线性。于是难以置信的最小圆覆盖的复杂度变成了线性的。

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 505
  12. #define LL long long
  13. #define INF 0xfffffff
  14. const double eps = 1e-;
  15. const double pi = acos(-1.0);
  16. const double inf = ~0u>>;
  17. struct point
  18. {
  19. double x,y;
  20. point(double x=,double y = ):x(x),y(y){}
  21. }p[N];
  22. typedef point pointt ;
  23. pointt operator -(point a,point b)
  24. {
  25. return point(a.x-b.x,a.y-b.y);
  26. }
  27. int dcmp(double x)
  28. {
  29. if(fabs(x)<eps) return ;
  30. return x<?-:;
  31. }
  32. double dis(point a)
  33. {
  34. return sqrt(a.x*a.x+a.y*a.y);
  35. }
  36. point circumcenter(point a, point b, point c)
  37. { //返回三角形的外心
  38. point ret;
  39. double a1 = b.x-a.x,b1 = b.y-a.y,c1 = (a1*a1+b1*b1)/;
  40. double a2 = c.x-a.x,b2 = c.y-a.y,c2 = (a2*a2+b2*b2)/;
  41. double d = a1*b2-a2*b1;
  42. ret.x=a.x+(c1*b2-c2*b1)/d;
  43. ret.y=a.y+(a1*c2-a2*c1)/d;
  44. return ret;
  45. }
  46. void min_cover_circle(point p[],int n,point &c,double &r)
  47. {
  48. random_shuffle(p,p+n);
  49. c = p[],r = ;
  50. int i,j,g;
  51. for(i = ; i < n ;i++)
  52. {
  53. if(dcmp(dis(p[i]-c)-r)>)
  54. {
  55. c = p[i];
  56. r = ;
  57. for(j = ; j < i ; j++)
  58. {
  59. if(dcmp(dis(p[j]-c)-r)>)
  60. {
  61. c = point((p[i].x+p[j].x)/,(p[i].y+p[j].y)/);
  62. r = dis(p[j]-c);
  63. for(g = ; g < j; g++)
  64. if(dcmp(dis(p[g]-c)-r)>)
  65. {
  66. c = circumcenter(p[i],p[j],p[g]);
  67. r = dis(p[i]-c);
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. int main()
  75. {
  76. int n,i;
  77. while(scanf("%d",&n)&&n)
  78. {
  79. for(i = ; i < n; i++)
  80. scanf("%lf%lf",&p[i].x,&p[i].y);
  81. point c;
  82. double r;
  83. min_cover_circle(p,n,c,r);
  84. printf("%.2f %.2f %.2f\n",c.x,c.y,r);
  85. }
  86. return ;
  87. }
  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 505
  12. #define LL long long
  13. #define INF 0xfffffff
  14. const double eps = 1e-;
  15. const double pi = acos(-1.0);
  16. const double inf = ~0u>>;
  17. struct point
  18. {
  19. double x,y;
  20. point(double x=,double y = ):x(x),y(y){}
  21. }p[N];
  22. typedef point pointt ;
  23. pointt operator -(point a,point b)
  24. {
  25. return point(a.x-b.x,a.y-b.y);
  26. }
  27. int dcmp(double x)
  28. {
  29. if(fabs(x)<eps) return ;
  30. return x<?-:;
  31. }
  32. double dis(point a)
  33. {
  34. return sqrt(a.x*a.x+a.y*a.y);
  35. }
  36. point circumcenter(point a, point b, point c)
  37. { //返回三角形的外心
  38. point ret;
  39. double a1 = b.x-a.x,b1 = b.y-a.y,c1 = (a1*a1+b1*b1)/;
  40. double a2 = c.x-a.x,b2 = c.y-a.y,c2 = (a2*a2+b2*b2)/;
  41. double d = a1*b2-a2*b1;
  42. ret.x=a.x+(c1*b2-c2*b1)/d;
  43. ret.y=a.y+(a1*c2-a2*c1)/d;
  44. return ret;
  45. }
  46. void min_cover_circle(point p[],int n,point &c,double &r)
  47. {
  48. random_shuffle(p,p+n);
  49. c = p[],r = ;
  50. int i,j,g;
  51. for(i = ; i < n ;i++)
  52. {
  53. if(dcmp(dis(p[i]-c)-r)>)
  54. {
  55. c = p[i];
  56. r = ;
  57. for(j = ; j < i ; j++)
  58. {
  59. if(dcmp(dis(p[j]-c)-r)>)
  60. {
  61. c = point((p[i].x+p[j].x)/,(p[i].y+p[j].y)/);
  62. r = dis(p[j]-c);
  63. for(g = ; g < j; g++)
  64. if(dcmp(dis(p[g]-c)-r)>)
  65. {
  66. c = circumcenter(p[i],p[j],p[g]);
  67. r = dis(p[i]-c);
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. int main()
  75. {
  76. int n,i;
  77. while(scanf("%d",&n)&&n)
  78. {
  79. for(i = ; i < n; i++)
  80. scanf("%lf%lf",&p[i].x,&p[i].y);
  81. point c;
  82. double r;
  83. min_cover_circle(p,n,c,r);
  84. printf("%.2f %.2f %.2f\n",c.x,c.y,r);
  85. }
  86. return ;
  87. }

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. Win7家庭版包“已停止工作”

    在VS2010上依据接口,写了个WiFi共享软件,在Win7旗舰班上正确无误,而在却在Win7家庭版上运行不了,报“已停止工作”错误. 解决方法: 1.下载安装vs2010对应的.Net平台:Micr ...

  2. window下appserv组合包配置asp标记风格与简短风格

    php一共有四种编码风格 分别为 :XML风格,脚本分铬,简短风格,ASP风格 如果要配置asp标记风格与简短风格,需要在php.ini文件中配置. 打开文件的位置C:\ window\php.ini ...

  3. [HTML]js实现页面跳转,页面A跳到另一个页面B.以及页面传值(中文)

    要实现从一个页面A跳到另一个页面B,js实现就在A的js代码加跳转代码 JS跳转大概有以下几种方式: 第一种:(跳转到b.html)<script language="javascri ...

  4. css弹性盒子学习

    css3弹性盒子是一种布局方式,在适应不同的屏幕大小的时候,能够确保元素拥有更恰当的排布行为.它只是视觉呈现上的,即显示顺序适应显示空间,与源代码无关,源代码顺序不受影响. 定义一个弹性盒子: 在cs ...

  5. 每日一九度之 题目1031:xxx定律

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6870 解决:4302 题目描述:     对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数 ...

  6. Android动画的使用总结

    1.补间动画(透明渐变.平移.旋转.缩放.组合) 方法一:通过xml文件设置 1-1:创建:res/anim 1-2:java代码写调用 Animation a = AnimationUtils.lo ...

  7. matlab mat文件读取和调用

    13.1 数据基本操作 本节介绍基本的数据操作,包括工作区的保存.导入和文件打开.13.1.1 文件的存储 MATLAB支持工作区的保存.用户可以将工作区或工作区中的变量以文件的形式保存,以备在需要时 ...

  8. Poj(1220),hash

    题目链接:http://poj.org/problem?id=1200 这个题,我真是无限MLE,RE,WA,太伤心了,还是写一下吧.题意很简单(英语很好读),最后看了一下金海峰的思路.果然,应该是我 ...

  9. HDU(3790),最短路二级标准

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3790 最短路径问题 Time Limit: 2000/1000 MS (Java/Others)    ...

  10. 搭建spring+mybatis+struts2环境的配置文件

    1.web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=& ...