Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 27110   Accepted: 9045

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.

Sample Input

9 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200

Sample Output

1628

Hint

结果四舍五入就可以了
 
题意不解释了,它的目的就是形成一个凸包,再加上一个半径是L的圆的周长;
和poj2187类似,这个题WA到死的原因是用G++交输出用 %.0f 而不是 %.0lf, 看了discuss才知道......
 
 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std; const int maxn = ;
const double PI = 3.1415926;
int stack[maxn],top;
int n,l; struct Point
{
int x,y;
}points[maxn]; int cmp(const Point &a, const Point &b)
{
if(a.y == b.y)
return a.x < b.x;
return a.y < b.y;
} int cross(const Point &p1,const Point &p2, const Point &p0)
{
return (p1.x-p0.x)*(p2.y-p0.y) - (p1.y-p0.y)*(p2.x-p0.x);
} double dis(const Point &a, const Point &b)
{
return sqrt((double)(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} void Graham()
{
sort(points,points+n,cmp);
stack[] = ;
stack[] = ;
top = ; for(int i = ; i < n; i++)
{
while(top >= && cross(points[i],points[stack[top]],points[stack[top-]]) >= )
top--;
stack[++top] = i;
} stack[++top] = n-;
int count = top; for(int i = n-; i >= ; i--)
{
while(top >= count && cross(points[i],points[stack[top]],points[stack[top-]]) >= )
top--;
stack[++top] = i;
}
} int main()
{
scanf("%d %d",&n,&l);
for(int i = ; i < n; i++)
scanf("%d %d",&points[i].x,&points[i].y); double ans = *PI*l;
Graham();
for(int i = ; i < top; i++)
{
ans += dis(points[stack[i]],points[stack[i+]]);
}
printf("%.0f\n",ans);
return ;
}
 

Wall(Graham算法)的更多相关文章

  1. Graham算法—二维点集VC++实现

    一.凸包定义 通俗的说就是:一组平面上的点,求一个包含所有点的最小凸多边形,这个最小凸多边形就是凸包. 二.Graham算法思想 概要:Graham算法的主要思想就是,最终形成的凸包,即包围所有点的凸 ...

  2. 平面凸包Graham算法

    板题hdu1348Wall 平面凸包问题是计算几何中的一个经典问题 具体就是给出平面上的多个点,求一个最小的凸多边形,使得其包含所有的点 具体形象就类似平面上有若干柱子,一个人用绳子从外围将其紧紧缠绕 ...

  3. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  4. POJ1113:Wall (凸包算法学习)

    题意: 给你一个由n个点构成的多边形城堡(看成二维),按顺序给你n个点,相邻两个点相连. 让你围着这个多边形城堡建一个围墙,城堡任意一点到围墙的距离要求大于等于L,让你求这个围墙的最小周长(看成二维平 ...

  5. 计算几何--求凸包模板--Graham算法--poj 1113

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28157   Accepted: 9401 Description ...

  6. nyoj-253-LK的旅行(Graham算法和旋转卡壳)

    题目链接 /* Name:nyoj-253-LK的旅行 Copyright: Author: Date: 2018/4/27 15:01:36 Description: zyj的模板 */ #incl ...

  7. nyoj-78-圈水池(Graham算法求凸包)

    题目链接 /* Name:nyoj-78-圈水池 Copyright: Author: Date: 2018/4/27 9:52:48 Description: Graham求凸包 zyj大佬的模板, ...

  8. 【计算几何初步-凸包-Graham扫描法-极角序】【HDU1348】 WALL

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  9. Beauty Contest(graham求凸包算法)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25256   Accepted: 7756 Description Bess ...

随机推荐

  1. HTTP协议 状态码详解

    http://www.cnblogs.com/TankXiao/archive/2013/01/08/2818542.html

  2. 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之二

    /** ****************************************************************************** * @author    暴走的小 ...

  3. HTML的Get方法URL传递中文参数,解决乱码问题

    本例中有使用JQuery. 资料参考:http://www.cnblogs.com/babycool/p/3169058.html 发送的HTML页面代码: <!DOCTYPE html> ...

  4. JS,JQuery杂谈

    JS返回页面: JS返回前一个页面,经常看到有人用window.history.go(-1)这种方法  这种放的确可以返回,也仅仅只是返回,返回的页面信息却没有刷新.也有人用windows.histo ...

  5. OUTPUT、Merge语句的使用

    新版本的数据库中增加了OUTPUT子句,这个很好用,详细的使用方式大家可以参考SQL的联机帮助文档.这里仅记录下常用的场景:在对数据库进行增删改的时候我们有时候需要记录日志(这里指将日志记录在DB中而 ...

  6. WCF系列学习5天速成

    看到一篇比较好的基础wcf学习博客,分享给大家:http://www.cnblogs.com/huangxincheng/archive/2011/10/23/2221845.html

  7. 那些年,我们一起学WCF--(6)PerCall实例行为

    当客户端调用服务器端服务后,服务器端就会为客户端生成一个实例,关于服务实例的分配问题,在WCF中有专门的属性进行设置,可以让所有客户端共享一个实例, 也可以让一个客户端可以拥有多个实例,也可以让一个实 ...

  8. (九)打印机驱动设置—USB接口的设置

    佳博打印机代理商淘宝店https://shop107172033.taobao.com/index.htm?spm=2013.1.w5002-9520741823.2.Sqz8Pf 在此店购买的打印机 ...

  9. C#获取类中所有方法

    var t = typeof(HomeController); //获取所有方法 System.Reflection.MethodInfo[] methods = t.GetMethods(); // ...

  10. TOM大师脚本-show space 多个版本,谢谢大牛们

    示例一 该脚本需区分 对象的管理方式是 自动还是 手动, 对手动管理方式 的表显示很全面 SQL> exec show_space_old('MAN_TAB','DEV','TABLE'); F ...