Maple trees

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 222 Accepted Submission(s): 79
 
Problem Description
There are a lot of trees in HDU. Kiki want to surround all the trees with the minimal required length of the rope . As follow,

To make this problem more simple, consider all the trees are circles in a plate. The diameter of all the trees are the same (the diameter of a tree is 1 unit). Kiki can calculate the minimal length of the rope , because it's so easy for this smart girl.
But we don't have a rope to surround the trees. Instead, we only have some circle rings of different radius. Now I want to know the minimal required radius of the circle ring. And I don't want to ask her this problem, because she is busy preparing for the examination.
As a smart ACMer, can you help me ?
 
Input
The input contains one or more data sets. At first line of each input data set is number of trees in this data set n (1 <= n <= 100), it is followed by n coordinates of the trees. Each coordinate is a pair of integers, and each integer is in [-1000, 1000], it means the position of a tree’s center. Each pair is separated by blank.
Zero at line for number of trees terminates the input for your program.
 
Output
Minimal required radius of the circle ring I have to choose. The precision should be 10^-2.
 
Sample Input
  1. 2
  2. 1 0
  3. -1 0
  4. 0
 
Sample Output
  1. 1.50
 
Author
zjt
 
 
Recommend
lcy
 
  1. /*
  2. 题意:给你散落的点,让你求出最小的圆,将这些点围起来,点可以在圆上,输出圆的最小半径。
  3.  
  4. 初步思路:求出凸包,然后在求出这个凸包的外接圆,两条边的垂直平分线的交点就是圆心
  5.  
  6. #错误:有点天真,三角形一定有外接圆,但是多边形不一定有外接圆
  7.  
  8. #改进:求出凸包,然后求凸包的最小覆盖圆,这个名词也是看到博客才知道了(呜呜呜,又少了
  9. 一次好好动脑的机会)然后任意的三个点组成的三角形的外接圆的最大半径就是就是凸包
  10. “外接圆”的半径了,三角形的外接圆半径为abc/4s,这个公式能简单的证明。遍历出所有的半径,中间最长的半径
  11. 就是要求的半径。
  12. #改进错误点:上面的情况只适用于锐角三角形,钝角,直角三角形的“外接圆”的最小半径,不是外接圆的半径,而是最长边的一半!
  13.  
  14. */
  15. #include<bits/stdc++.h>
  16. using namespace std;
  17. /****************************凸包模板*******************************/
  18. const double eps = 1e-;
  19. int sgn(double x)
  20. {
  21. if(fabs(x) < eps)return ;
  22. if(x < )return -;
  23. else return ;
  24. }
  25. struct Point
  26. {
  27. double x,y;
  28. Point(){}
  29. Point(double _x,double _y)
  30. {
  31. x = _x;y = _y;
  32. }
  33. Point operator -(const Point &b)const
  34. {
  35. return Point(x - b.x,y - b.y);
  36. }
  37. //叉积
  38. double operator ^(const Point &b)const
  39. {
  40. return x*b.y - y*b.x;
  41. }
  42. //点积
  43. double operator *(const Point &b)const
  44. {
  45. return x*b.x + y*b.y;
  46. }
  47. void input(){
  48. scanf("%lf%lf",&x,&y);
  49. }
  50. };
  51. struct Line {
  52. Point s,e;
  53. Line(){}
  54. Line(Point _s,Point _e) {
  55. s = _s; e = _e;
  56. }
  57. };
  58. //*两点间距离
  59. double dist(Point a,Point b)
  60. {
  61. return sqrt((a-b)*(a-b));
  62. }
  63. /*
  64. * 求凸包,Graham算法
  65. * 点的编号0~n-1
  66. * 返回凸包结果Stack[0~top-1]为凸包的编号
  67. */
  68. const int MAXN = ;
  69. Point List[MAXN];
  70. int Stack[MAXN];//用来存放凸包的点
  71. int top;//表示凸包中点的个数
  72. //相对于List[0]的极角排序
  73. bool _cmp(Point p1,Point p2)
  74. {
  75. double tmp = (p1-List[])^(p2-List[]);
  76. if(sgn(tmp) > )
  77. return true;
  78. else if(sgn(tmp) == && sgn(dist(p1,List[]) - dist(p2,List[])) <= )
  79. return true;
  80. else
  81. return false;
  82. }
  83. void Graham(int n)
  84. {
  85. Point p0;
  86. int k = ;
  87. p0 = List[];
  88. //找最下边的一个点
  89. for(int i = ;i < n;i++)
  90. {
  91. if( (p0.y > List[i].y) || (p0.y == List[i].y && p0.x > List[i].x) )
  92. {
  93. p0 = List[i];
  94. k = i;
  95. }
  96. }
  97. swap(List[k],List[]);
  98. sort(List+,List+n,_cmp);
  99. if(n == )
  100. {
  101. top = ;
  102. Stack[] = ;
  103. return;
  104. }
  105. if(n == )
  106. {
  107. top = ;
  108. Stack[] = ;
  109. Stack[] = ;
  110. return ;
  111. }
  112. Stack[] = ;
  113. Stack[] = ;
  114. top = ;
  115. for(int i = ;i < n;i++)
  116. {
  117. while(top > && sgn((List[Stack[top-]]-List[Stack[top-]])^(List[i]-List[Stack[top-]])) <= )
  118. top--;
  119. Stack[top++] = i;
  120. }
  121. }
  122. /****************************凸包模板*******************************/
  123. int n;
  124. int main(){
  125. // freopen("in.txt","r",stdin);
  126. while(scanf("%d",&n)!=EOF&&n){
  127. for(int i=;i<n;i++){
  128. List[i].input();
  129. }//输入所有点坐标
  130. if(n==){
  131. printf("0.50\n");
  132. continue;
  133. }
  134. if(n==){
  135. printf("%.2lf\n",dist(List[],List[])/+0.5);
  136. continue;
  137. }
  138. Graham(n);//求出凸包
  139. double Maxr=-1.0;
  140. // cout<<top<<endl;
  141. //将Static[0]作为所有小三角形的公共顶点
  142. for(int i=;i<top;i++){//枚举三角形的点
  143. for(int j=i+;j<top;j++){
  144. for(int k=j+;k<top;k++){
  145. /*
  146. 三条边的长度
  147. */
  148. double a=dist(List[Stack[i]],List[Stack[j]]);
  149. double b=dist(List[Stack[i]],List[Stack[k]]);
  150. double c=dist(List[Stack[k]],List[Stack[j]]);
  151. if(a*a+b*b<c*c||a*a+c*c<b*b||b*b+c*c<a*a){//判断是不是锐角三角形
  152. Maxr=max(Maxr,max(max(a,b),c)/);
  153. }else{
  154. /*
  155. 三角形的面积
  156. */
  157. Point x1=List[Stack[j]]-List[Stack[i]];
  158. Point x2=List[Stack[k]]-List[Stack[i]];
  159. double s=fabs(x1^x2)/;
  160. Maxr=max(Maxr,(a*b*c)/(*s));
  161. }
  162. }
  163. }
  164. }
  165. printf("%.2lf\n",Maxr+0.5);
  166. }
  167. return ;
  168. }

Maple trees(最小覆盖圆)的更多相关文章

  1. (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)

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

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

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

  3. zoj 1450 Minimal Circle 最小覆盖圆

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450 You are to write a program to fi ...

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

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

  5. HDU 2215 Maple trees

    增量法的最小包围圈算法,不会…… #include <cstdio> #include <cstring> #include <iostream> #include ...

  6. [matlab] 10.最小覆盖

    clear all; close all; clc; n=100; p=rand(n,2); p1=p(1,:); %取第一行的值 P1点 p2=p(2,:); %取第二行的值 P2点 r=sqrt( ...

  7. [SHTSC 2014] 信号增幅仪

    最小覆盖圆算法.看着题解半蒙半抄的搞过去了… 主要参考以下http://blog.csdn.net/acdreamers/article/details/9406735http://blog.csdn ...

  8. BZOJ1946 : [Ceoi2006]ANTENNA

    首先通过随机增量法求出最小覆盖圆,作为答案的上界. 然后二分答案,检验的时候枚举每个点作为原点,求出其他每个点被包括在圆内的角度区间,然后扫描线即可. 时间复杂度$O(Tn^2\log n)$. #i ...

  9. 【BZOJ】2823: [AHOI2012]信号塔

    题意 给\(n\)个点,求一个能覆盖所有点的面积最小的圆.(\(n \le 50000\)) 分析 随机增量法 题解 理论上\(O(n^3)\)暴力,实际上加上随机化后期望是\(O(n)\)的. 算法 ...

随机推荐

  1. 彻底弄懂AngularJS中的transclusion

    点击查看AngularJS系列目录 彻底弄懂AngularJS中的transclusion AngularJS中指令的重要性是不言而喻的,指令让我们可以创建自己的HTML标记,它将自定义元素变成了一个 ...

  2. Storm同步调用之DRPC模型探讨

    摘要:Storm的编程模型是一个有向无环图,决定了storm的spout接收到外部系统的请求后,spout并不能得到bolt的处理结果并将结果返回给外部请求.所以也就决定了storm无法提供对外部系统 ...

  3. mac pycharm 里table键设置为4个空格键

    Operation flow: File--Default Settings editor--code style--python

  4. Thirft框架快速入门

    Thrift介绍1.什么是thrift?thrift早期由facebook内部团队开发,主要用于实现跨语言间的方法调用,属于远程方法调用的一种,后开源纳入apache中,成为了apache thrif ...

  5. SVN初体验

    呐,部门领导要求今后项目部分内容要实行版本控制,因此有机会深入接触下SVN这门功课 ---------------------------------------------------------- ...

  6. REST架构概述

    REST概述 REST(英文:Representational State Transfer,简称REST)描述了一个架构样式的网络系统,比如 web 应用程序.它首次出现在 2000 年 Roy F ...

  7. jQuery中下拉select、复选checkbox、单选radio的操作代码

    //select $("#Icon") //对象 $("#Icon").val() //取值 $("#Icon").val("fa ...

  8. html加载时事件触发顺序

    一般情况下页面的响应加载顺序时,域名解析-加载html-加载js和css-加载图片等其他信息. jq ready()的方法就是Dom Ready,他的作用或者意义就是:在DOM加载完成后就可以可以对D ...

  9. Spring+JUnit4单元测试入门

    (一).JUnit介绍 JUnit是Java中最有名的单元测试框架,多数Java的开发环境都已经集成了JUnit作为单元测试的工具.好的单元测试能极大的提高开发效率和代码质量. Maven导入juni ...

  10. BaseServlet,让一个servlet处理多个请求

    BaseServlet 第一次学习servlet的时候是跟着传智播客免费的教学视频,其中崔希凡讲的是我学过自认讲的最好的一位,BaseServlet也是跟着他写过一次,当时很多东西不能理解,后来慢慢发 ...