题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450

You are to write a program to find a circle which covers a set of points and has the minimal area. There will be no more than 100 points in one problem.

题意描述:找到一个最小圆能够包含到所有的二维坐标点。

算法分析:最小覆盖圆的做法。

  1. //最小覆盖圆
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<cmath>
  7. #include<algorithm>
  8. #define inf 0x7fffffff
  9. #define exp 1e-10
  10. #define PI 3.141592654
  11. using namespace std;
  12. const int maxn=+;
  13. struct Point
  14. {
  15. double x,y;
  16. Point(double x=,double y=):x(x),y(y){}
  17. }an[maxn],d;//d:最小覆盖圆的圆心坐标
  18. double r;//最小覆盖圆的半径
  19. typedef Point Vector;
  20. Vector operator + (Vector A,Vector B) {return Vector(A.x+B.x , A.y+B.y); }
  21. Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x , A.y-B.y); }
  22. Vector operator * (Vector A,double p) {return Vector(A.x*p , A.y*p); }
  23. Vector operator / (Vector A,double p) {return Vector(A.x/p , A.y/p); }
  24. int dcmp(double x)
  25. {
  26. if (fabs(x)<exp) return ;
  27. return x< ? - : ;
  28. }
  29. double cross(Vector A,Vector B)
  30. {
  31. return A.x*B.y-B.x*A.y;
  32. }
  33. double dist(Vector A,Vector B)
  34. {
  35. double x=(A.x-B.x)*(A.x-B.x);
  36. double y=(A.y-B.y)*(A.y-B.y);
  37. return sqrt(x+y);
  38. }
  39.  
  40. void MiniDiscWith2Point(Point p,Point q,int n)
  41. {
  42. d=(p+q)/2.0;
  43. r=dist(p,q)/;
  44. int k;
  45. double c1,c2,t1,t2,t3;
  46. for (k= ;k<=n ;k++)
  47. {
  48. if (dist(d,an[k])<=r) continue;
  49. if (dcmp(cross(p-an[k],q-an[k]))!=)
  50. {
  51. c1=(p.x*p.x+p.y*p.y-q.x*q.x-q.y*q.y)/2.0;
  52. c2=(p.x*p.x+p.y*p.y-an[k].x*an[k].x-an[k].y*an[k].y)/2.0;
  53. d.x=(c1*(p.y-an[k].y)-c2*(p.y-q.y))/((p.x-q.x)*(p.y-an[k].y)-(p.x-an[k].x)*(p.y-q.y));
  54. d.y=(c1*(p.x-an[k].x)-c2*(p.x-q.x))/((p.y-q.y)*(p.x-an[k].x)-(p.y-an[k].y)*(p.x-q.x));
  55. r=dist(d,an[k]);
  56. }
  57. else
  58. {
  59. t1=dist(p,q);
  60. t2=dist(q,an[k]);
  61. t3=dist(p,an[k]);
  62. if (t1>=t2 && t1>=t3)
  63. {
  64. d=(p+q)/2.0;
  65. r=dist(p,q)/2.0;
  66. }
  67. else if (t2>=t1 && t2>=t3)
  68. {
  69. d=(an[k]+q)/2.0;
  70. r=dist(an[k],q)/2.0;
  71. }
  72. else
  73. {
  74. d=(an[k]+p)/2.0;
  75. r=dist(an[k],p)/2.0;
  76. }
  77. }
  78. }
  79. }
  80. void MiniDiscWithPoint(Point p,int n)
  81. {
  82. d=(p+an[])/2.0;
  83. r=dist(p,an[])/2.0;
  84. int j;
  85. for (j= ;j<=n ;j++)
  86. {
  87. if (dist(d,an[j])<=r) continue;
  88. else
  89. {
  90. MiniDiscWith2Point(p,an[j],j-);
  91. }
  92. }
  93. }
  94.  
  95. int main()
  96. {
  97. int n;
  98. while (scanf("%d",&n)!=EOF && n)
  99. {
  100. for (int i= ;i<=n ;i++)
  101. {
  102. scanf("%lf%lf",&an[i].x,&an[i].y);
  103. }
  104. if (n==)
  105. {
  106. printf("%lf %lf\n",an[].x,an[].y);
  107. continue;
  108. }
  109. r=dist(an[],an[])/2.0;
  110. d=(an[]+an[])/2.0;
  111. for (int i= ;i<=n ;i++)
  112. {
  113. if (dist(d,an[i])<=r) continue;
  114. else
  115. MiniDiscWithPoint(an[i],i-);
  116. }
  117. printf("%.2lf %.2lf %.2lf\n",d.x,d.y,r);
  118. }
  119. return ;
  120. }

zoj 1450 Minimal Circle 最小覆盖圆的更多相关文章

  1. HDU 3007 Buried memory & ZOJ 1450 Minimal Circle

    题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...

  2. ZOJ 1450 Minimal Circle 最小圆覆盖

    套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...

  3. Maple trees(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  4. [hdu-3007]Buried memory 最小覆盖圆

    大致题意: 平面上有n个点,求一个最小的圆覆盖住所有点 最小覆盖圆裸题 学习了一波最小覆盖圆算法 #include<cstdio> #include<iostream> #in ...

  5. ZOJ1450 Minimal Circle 最小圆覆盖

    ZOJ1450 给定N个点(N<=100)求最小的圆把这些点全部覆盖 考虑对于三角形,可以唯一的找到外接圆,而多边形又可以分解为三角形,所以对于多边形也可以找到唯一的最小覆盖圆. #includ ...

  6. ZOJ1450 Minimal Circle

    You are to write a program to find a circle which covers a set of points and has the minimal area. T ...

  7. hdu 2215 & hdu 3932(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. [LeetCode] Generate Random Point in a Circle 生成圆中的随机点

    Given the radius and x-y positions of the center of a circle, write a function randPoint which gener ...

  9. Judge Route Circle --判断圆路线

    Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...

随机推荐

  1. Filestream读取或写入文件

    using System.IO;//引用 System.IO namespace filestream { public partial class Form1 : Form { public For ...

  2. Vue.js学习 Item12 – 内部响应式原理探究

    深入响应式原理 大部分的基础内容我们已经讲到了,现在讲点底层内容.Vue.js 最显著的一个功能是响应系统 —— 模型只是普通对象,修改它则更新视图.这让状态管理非常简单且直观,不过理解它的原理也很重 ...

  3. 工作中nginx配置文件的一些参数记录

    reset_timedout_connection on 告诉nginx关闭不响应的客户端连接.这将会释放那个客户端所占有的内存空间 tcp_nopush on 告诉nginx在一个数据包里发送许多个 ...

  4. Hbase Interface HConnection

    HTablePool 在Hbase 0.94.0.95.0.97被废弃,在0.98中被清除( HTablePool 对比HConnection.getTable),hbase0.98 HTablePo ...

  5. Ueditor防止代码自动清除

    Ueditor功能真的很牛逼,可也有让人悲催的地方,尤其是自动清除代码,会将你默认的div标签改成p,挺让人闹心的,不过Ueditor的开发人员还是满热心的,搜遍网上无答案的时候,问了下他们,解决了 ...

  6. 亚信联创--java面试题目总结

    这几天投简历,只有两家的HR表示感兴趣.易思卓越和亚信联创,不管怎样如果能有机会面试都一定尽力表现,所以找了找网上的面经,这里先把题目总结一下. 职位要求如下: ------------------- ...

  7. RecyclerView的基本创建

    线性显示 类似于listview: 线性宫格显示 类似于grid view: 用线性宫格显示 类似于瀑布流: 结构图: 测试代码: activity_main.xml: <RelativeLay ...

  8. Android计时器TimerTask,Timer,Handler

    Android计时器TimerTask,Timer,若要在TimerTask中更新主线程UI,鉴于Android编程模型不允许在非主线程中更新主线程UI,因此需要结合Android的Handler实现 ...

  9. char型变量理解

    char  c = 128; printf("%d", c); 问输出是多少? 正确答案应该是-128. 如下几种情况: char c=128;printf("%u\n& ...

  10. 学习XML总结

    XML 元素指的是从(且包括)开始标签直到(且包括)结束标签的部分. 元素可包含其他元素.文本或者两者的混合物.元素也可以拥有属性. xml包含如下: 元素 文本 属性 元素 命名: 名称可以含字母. ...