Wall

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

Total Submission(s): 3779    Accepted Submission(s): 1066

Problem Description
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall
towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources
to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build
the wall.

Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.








The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices
in feet.
 
Input
The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to
the castle.



Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides
of the castle do not intersect anywhere except for vertices.
 
Output
Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers
are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.



This problem contains multiple test cases!



The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.



The output format consists of N output blocks. There is a blank line between output blocks.
 
Sample Input
  1. 1
  2. 9 100
  3. 200 400
  4. 300 400
  5. 300 300
  6. 400 300
  7. 400 400
  8. 500 400
  9. 500 200
  10. 350 200
  11. 200 200
 
Sample Output
  1. 1628
 
Source
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  2150 1147 1558 2202 1374 
 

Statistic | Submit | Discuss | Note

 

题目本身不多说了

ANS=凸包周长+2*R*L 很容易证明

Graham算法的话 代码注释也有点解释

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <ctime>
  6. #include <algorithm>
  7. #include <iostream>
  8. #include <sstream>
  9. #include <string>
  10. #define oo 0x13131313
  11. #define pi 3.1415926
  12. #define exp 10e-6
  13. using namespace std;
  14. int N,L;
  15. struct point{
  16. double x,y;
  17. };
  18. point A[1050];
  19. point stk[1050];
  20. int s=0;
  21. int k;
  22. int start;
  23. double ans;
  24.  
  25. double dist(point a,point b)
  26. {
  27. return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  28. }
  29. double crossdet(double x1,double y1,double x2,double y2)
  30. {
  31. return x1*y2-x2*y1;
  32. }
  33. double cross(point a,point b,point c)
  34. {
  35. return crossdet(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
  36. }
  37. double dotdet(double x1,double y1,double x2,double y2)
  38. {
  39. return x1*x2+y1*y2;
  40. }
  41. double dot(point a,point b,point c)
  42. {
  43. return dotdet(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
  44. }
  45. int sgn(double x)
  46. {
  47. if(fabs(x)<exp) return 0;
  48. if(x<0) return -1;
  49. else return 1;
  50. }int cmp(point a,point b) // 当叉积为0时通过点积比较的cmp
  51. {
  52. double temp=cross(A[1],a,b);
  53. double temp1;
  54. if(sgn(temp)==0)
  55. {
  56. temp1=dot(a,A[1],b);
  57. return sgn(temp1)<0; // 点靠起点近的排前面
  58. }
  59. else return sgn(temp)>0;
  60. }
  61. /*
  62. int cmp(point a,point b) //当叉积为0时通过距离比较的cmp
  63. {
  64. double temp=cross(A[1],a,b);
  65. double temp1;
  66. if(sgn(temp)==0)
  67. {
  68. return dist(a,A[1])<dist(b,A[1]);
  69. }
  70. else return sgn(temp)>0;
  71. }
  72. /*
  73. int cmp(const void *i,const void *j) //qsort的cmp
  74. {
  75. point *a=(point *)i,*b=(point *)j;
  76. double re=cross(A[1],*a,*b);
  77. if(re==0)
  78. return dist(*a,A[1])>dist(*b,A[1]);
  79. return re<0;
  80. }
  81. */
  82. void input()
  83. {
  84. memset(stk,0,sizeof(stk));
  85. memset(A,0,sizeof(A));
  86. s=0;ans=0;
  87. cin>>N>>L;
  88. for(int i=1;i<=N;i++)
  89. {
  90. scanf("%lf%lf",&A[i].x,&A[i].y);
  91. }
  92. }
  93. void findmin(int &k) //寻找最小的y,同时最小的话选x小的
  94. {
  95. k=1;
  96. for(int i=2;i<=N;i++)
  97. {
  98. if(sgn(A[i].y-A[k].y)<0)
  99. k=i;
  100. else if(sgn(A[i].y-A[k].y)==0&&(A[i].x-A[k].x)<0)
  101. k=i;
  102. }
  103. }
  104. void solve()
  105. {
  106. findmin(start);
  107. swap(A[1],A[start]);//小细节注意
  108. // qsort(A+2,N-1,sizeof(A[1]),cmp);
  109. sort(A+2,A+N+1,cmp);
  110. for(int i=1;i<=2;i++)
  111. {
  112. stk[++s]=A[i]; //一开始二个肯定在的点入栈
  113. }
  114. for(int i=3;i<=N;i++)
  115. {
  116. while(sgn(cross(stk[s-1],stk[s],A[i]))<=0&&s>=2) //1.防止下面的2个点退栈 2.若stk[i-1]A[i]不在stk[i-1]A[s]的逆时针方向 退栈 寻找更好的凸包
  117. s--;
  118. stk[++s]=A[i]; //入栈 最终栈里面至少有3个点 也显然可知若即使只有3个点 则3个点都在凸包上
  119. }
  120. for(int i=2;i<=s;i++)
  121. {
  122. ans+=dist(stk[i],stk[i-1]);
  123. }
  124. ans+=dist(stk[1],stk[s]);
  125. }
  126. void init()
  127. {
  128. freopen("a.in","r",stdin);
  129. freopen("a.out","w",stdout);
  130. }
  131. int main()
  132. {
  133. int T;
  134. //init();
  135. cin>>T;
  136. int ttt=0;
  137. while(T--)
  138. {
  139. if(ttt++) printf("\n");
  140. input();
  141. solve();
  142. if(N==1) ans=0;
  143. else if(N==2) ans=dist(A[1],A[2]);
  144. ans=ans+2*pi*L; //由题目显然克制 凸包周长加那个圆的面积
  145. printf("%.0lf\n",ans);
  146. }
  147. }

【计算几何初步-凸包-Graham扫描法-极角序】【HDU1348】 WALL的更多相关文章

  1. [hdu contest 2019-07-29] Azshara's deep sea 计算几何 动态规划 区间dp 凸包 graham扫描法

    今天hdu的比赛的第一题,凸包+区间dp. 给出n个点m个圆,n<400,m<100,要求找出凸包然后给凸包上的点连线,连线的两个点不能(在凸包上)相邻,连线不能与圆相交或相切,连线不能相 ...

  2. poj 1696:Space Ant(计算几何,凸包变种,极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2876   Accepted: 1839 Descrip ...

  3. 凸包--Graham扫描法

    一直听大佬们说:凸包.凸包.凸包 一直不会..... 然后.... 今天考试,考了一道计算几何的简单题.... 这,,,还是学一下吧.. 然后考试现场学习一下凸包算法. 先理解一下凸包是啥东西. 看看 ...

  4. 【计算几何初步-凸包-Jarvis步进法。】【HDU1392】Surround the Trees

    [科普]什么是BestCoder?如何参加? Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  5. 凸包算法(Graham扫描法)详解

    先说下基础知识,不然不好理解后面的东西 两向量的X乘p1(x1,y1),p2(x2,y2) p1Xp2如果小于零则说明  p1在p2的逆时针方向 如果大于零则说明 p1在p2的顺时针方向 struct ...

  6. hrbustoj 1318:蛋疼的蚂蚁(计算几何,凸包变种,叉积应用)

    蛋疼的蚂蚁 Time Limit: 1000 MS     Memory Limit: 65536 K Total Submit: 39(22 users)    Total Accepted: 26 ...

  7. 计算几何 : 凸包学习笔记 --- Graham 扫描法

    凸包 (只针对二维平面内的凸包) 一.定义 简单的说,在一个二维平面内有n个点的集合S,现在要你选择一个点集C,C中的点构成一个凸多边形G,使得S集合的所有点要么在G内,要么在G上,并且保证这个凸多边 ...

  8. 凸包模板——Graham扫描法

    凸包模板--Graham扫描法 First 标签: 数学方法--计算几何 题目:洛谷P2742[模板]二维凸包/[USACO5.1]圈奶牛Fencing the Cows yyb的讲解:https:/ ...

  9. Graham 扫描法找凸包(convexHull)

    凸包定义 通俗的话来解释凸包:给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有的点  Graham扫描法 由最底的一点 \(p_1\) 开始(如果有多个这样的点, ...

随机推荐

  1. (转) unity 在移动平台中,文件操作路径详解

    http://www.unitymanual.com/thread-23491-1-1.html 今天,这篇文章其实是个老生常谈的问题咯,在网上类似的文章也比比皆是,在此我只是做个详细总结方便大家能够 ...

  2. 实现Android操作系统11种传感器介绍

    在Android2.3 gingerbread系统中,google提供了11种传感器供应用层使用. #define SENSOR_TYPE_ACCELEROMETER 1 //加速度 #define ...

  3. Android系统默认Home应用程序(Launcher)的启动过程源代码分析

    在前面一篇文章中,我们分析了Android系统在启动时安装应用程序的过程,这些应用程序安装好之后,还需要有一个 Home应用程序来负责把它们在桌面上展示出来,在Android系统中,这个默认的Home ...

  4. oracle函数Lpad与Rpad

    函数介绍 lpad函数从左边对字符串使用指定的字符进行填充.从其字面意思也可以理解,l是left的简写,pad是填充的意思,所以lpad就是从左边填充的意思. 语法格式如下: lpad( string ...

  5. linux学习记录 常用指令大全

    1.开启关闭服务器(即时生效): service iptasbles start service iptasbles stop 2.在开启了防火墙时,做如下设置,开启相关端口, 修改/etc/sysc ...

  6. 爆出错误:The Geometry has no Z values

    ArcGis添加地图标注,爆出错误:The Geometry has no Z values 解决方法如下: public bool AddFeature( ESRI.ArcGIS.Geometry. ...

  7. JS闭包(一)

    闭包是指有权访问另一个函数作用域中的变量的函数. 创建闭包的常见方法:在一个函数内部创建另一个函数. 对彻底理解闭包,需要知道如何创建作用域链以及作用域链有什么作用的细节. 闭包的功能: 保存函数执行 ...

  8. spring 上传图片

    @RequestMapping(value = "/upload",method = RequestMethod.POST) public String upload(@Reque ...

  9. javascript写的新闻滚动代码

    在企业站中,我们会看到很多新闻列表很平滑的滚动,但是这种功能自己写太浪费时间,下面是我整理好的一组很常用的新闻列表滚动,有上下分页哦! 1.body里面 <div class="tz_ ...

  10. 15个顶级Java多线程面试题及回答

    Java 线程面试问题 在任何Java面试当中多线程和并发方面的问题都是必不可少的一部分.如果你想获得任何股票投资银行的前台资讯职位,那么你应该准备很多关于多线程 的问题.在投资银行业务中多线程和并发 ...