Surround the Trees

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Problem Description
There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope. However, he does not know how to calculate it. Can you help him? 
The diameter and length of the trees are omitted, which means a tree can be seen as a point. The thickness of the rope is also omitted which means a rope can be seen as a line.

There are no more than 100 trees.

 
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, it is followed by series of coordinates of the trees. Each coordinate is a positive integer pair, and each integer is less than 32767. Each pair is separated by blank.

Zero at line for number of trees terminates the input for your program.

 
Output
The minimal length of the rope. The precision should be 10^-2.
 
Sample Input
9
12 7
24 9
30 5
41 9
80 7
50 87
22 9
45 1
50 7
0
 
Sample Output
243.06
 
Source
  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include<string>
  6. #include<queue>
  7. #include<algorithm>
  8. #include<stack>
  9. #include<cstring>
  10. #include<vector>
  11. #include<list>
  12. #include<bitset>
  13. #include<set>
  14. #include<map>
  15. #include<time.h>
  16. using namespace std;
  17. #define LL long long
  18. #define pi (4*atan(1.0))
  19. #define eps 1e-8
  20. #define bug(x) cout<<"bug"<<x<<endl;
  21. const int N=1e5+,M=1e6+,inf=1e9+;
  22. const LL INF=1e18+,mod=1e9+;
  23.  
  24. const int MAXN = ;
  25. struct Point
  26. {
  27. double x,y;
  28. Point() {}
  29. Point(double _x,double _y)
  30. {
  31. x = _x;
  32. y = _y;
  33. }
  34. Point operator -(const Point &b)const
  35. {
  36. return Point(x - b.x,y - b.y);
  37. }
  38. //叉积
  39. double operator ^(const Point &b)const
  40. {
  41. return x*b.y - y*b.x;
  42. }
  43. //点积
  44. double operator *(const Point &b)const
  45. {
  46. return x*b.x + y*b.y;
  47. }
  48. //绕原点旋转角度B(弧度值),后x,y的变化
  49. void transXY(double B)
  50. {
  51. double tx = x,ty = y;
  52. x= tx*cos(B) - ty*sin(B);
  53. y= tx*sin(B) + ty*cos(B);
  54. }
  55. };
  56. double dist(Point a,Point b)
  57. {
  58. return sqrt((a-b)*(a-b));
  59. }
  60. int sgn(double x)
  61. {
  62. if(fabs(x) < eps)return ;
  63. if(x < )return -;
  64. else return ;
  65. }
  66. Point listt[MAXN];
  67. int Stack[MAXN],top,n; //相对于listt[0]的极角排序
  68. bool _cmp(Point p1,Point p2)
  69. {
  70. double tmp = (p1-listt[])^(p2-listt[]);
  71. if(sgn(tmp) > )return true;
  72. else if(sgn(tmp) == && sgn(dist(p1,listt[]) - dist(p2,listt[])) <= ) return true;
  73. else return false;
  74. }
  75. void Graham(int n)
  76. {
  77. top=;
  78. Point p0;
  79. int k = ;
  80. p0 = listt[]; //找最下边的一个点
  81. for(int i = ; i < n; i++)
  82. {
  83. if( (p0.y > listt[i].y) || (p0.y == listt[i].y && p0.x > listt[i].x) )
  84. {
  85. p0 = listt[i];
  86. k = i;
  87. }
  88. }
  89. swap(listt[k],listt[]);
  90. sort(listt+,listt+n,_cmp);
  91. if(n == )
  92. {
  93. top = ;
  94. Stack[] = ;
  95. printf("0.00\n");
  96. return;
  97. }
  98. if(n == )
  99. {
  100. top = ;
  101. Stack[] = ;
  102. Stack[] = ;
  103. double dis=dist(listt[Stack[]],listt[Stack[]]);
  104. printf("%.2f\n",dis);
  105. return ;
  106. }
  107. Stack[] = ;
  108. Stack[] = ;
  109. top = ;
  110. for(int i = ; i < n; i++)
  111. {
  112. while(top > && sgn((listt[Stack[top-]]-listt[Stack[top-]])^(listt[i]-listt[Stack[top-]])) <= )
  113. top--;
  114. Stack[top++] = i;
  115. }
  116. double ans=;
  117. for(int i=; i<top; i++)
  118. {
  119. ans+=dist(listt[Stack[i]],listt[Stack[i-]]);
  120. }
  121. ans+=dist(listt[Stack[top-]],listt[Stack[]]);
  122. printf("%.2f\n",ans);
  123. }
  124. int main ()
  125. {
  126. while(~scanf ( "%d", &n ) )
  127. {
  128. if(!n)break;
  129. for(int i=; i<n; i++)
  130. scanf ( "%lf%lf", &listt[i].x, &listt[i].y );
  131. Graham(n);
  132. }
  133. return ;
  134. }

hdu 1392 Surround the Trees 凸包裸题的更多相关文章

  1. HDU 1392 Surround the Trees (凸包周长)

    题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...

  2. HDU - 1392 Surround the Trees (凸包)

    Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

  3. hdu 1392 Surround the Trees 凸包模板

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  4. hdu 1392 Surround the Trees (凸包)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  5. HDU 1392 Surround the Trees(凸包*计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...

  6. HDU 1392 Surround the Trees(凸包入门)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. hdu 1392:Surround the Trees(计算几何,求凸包周长)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. HDUJ 1392 Surround the Trees 凸包

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. 计算几何(凸包模板):HDU 1392 Surround the Trees

    There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So a ...

随机推荐

  1. GUI常用对象的属性

    %常用对象的属性 %.figure %hf=figure; %get(hf); %改变颜色 set Color %set(hf,'Color','w'); %去掉默认的菜单 Menubar %set( ...

  2. 计蒜客--移除数组中的重复元素 (set)

    给定一个升序排列的数组,去掉重复的数,并输出新的数组的长度. 例如:数组 A = \{1, 1, 2\}A={1,1,2},你的程序应该输出 22 即新数组的长度,新数组为 \{1, 2\}{1,2} ...

  3. windows与linux ping 显示的ip不一样

    DNS修改了一下域名对应的IP后,域名不能访问了,我在windows下ping一下域名,IP没有变过来,还是老的IP.我在linux下又ping了一下域名,是换过了的.这个问题是由windows下的本 ...

  4. Django之MVC和MTV

    一. MVC MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式: Model(模型)表示应用程序核心(比如数据库记录列表). ...

  5. 爬虫之牛掰的scrapy框架

    一. Scrapy简介及安装 http://python.jobbole.com/86405/ Scrapy的详细介绍   1.简介   2.安装     1.window上安装:         先 ...

  6. Android Camera2 预览,拍照,人脸检测并实时展现

    https://www.jianshu.com/p/5414ba2b5508 背景     最近需要做一个人脸检测并实时预览的功能.就是边检测人脸,边在预览界面上框出来.     当然本人并不是专门做 ...

  7. Linux学习笔记之Linux环境变量总结

    0x00 概述 Linux是一个多用户多任务的操作系统,可以在Linux中为不同的用户设置不同的运行环境,具体做法是设置不同用户的环境变量. 0x01 Linux环境变量分类 按照生命周期来分,Lin ...

  8. php+redis,延迟任务 实现自动取消订单,自动完成订单

    简单定时任务解决方案:使用redis的keyspace notifications(键失效后通知事件) 需要注意此功能是在redis 2.8版本以后推出的,因此你服务器上的reids最少要是2.8版本 ...

  9. VMware无法读取USB文件

    今天碰到虚拟机内的Mac OS无法读取USB,经过一番查看,是Windows的服务里面的vmware usb arbitration service服务没有启动,再点击启动的时候,报错,提示本地文件找 ...

  10. linux command line send email

    https://www.tecmint.com/send-email-attachment-from-linux-commandline/ https://stackoverflow.com/ques ...