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. RSA 加解密 签名 示例

    import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.FileOutputStrea ...

  2. Unity3D GUI之自定义风格组件

    GUI中可以使用一些默认的组件,里面的最后一个参数一般情况下,不设置就是默认的 ,当然也可以进行手动的指定,比如: GUI.Button(new Rect(0,0,100,100),"开始游 ...

  3. Axiom3D学习日记 0.Axiom基础知识

    Axiom 3D Engine An open-source, cross-platform, managed 3D rendering engine for DirectX, XNA and Ope ...

  4. 学习java随笔第一篇:搭建java平台(java se)

    电脑系统:windows8 在这里介绍一下java平台的3个版本: Java SE--Java Standard Edition,Java的标准版,主要用于桌面级的应用和数据库开发. Java EE- ...

  5. 在vSphere5.0虚拟机里的Ubuntu Server 32位安装JDK

    本机操作系统Win7 服务器用vSphere 5.0 虚拟机  在虚拟机安装了Ubuntu Server 12.04 1.首先到Oracle官网上下载jdk-7u51-linux-i586.tar.g ...

  6. oracle命令的缩写原型单词方便记忆总结

    $ORACLE_HOME/bin下的utilities解释 Binary              First Available        Description adapters        ...

  7. ios-pch文件的手动添加

    Xcode6添加pch文件 前言:Xcode6中不在为开发者自动创建pch文件,在pch文件中我们可以添加一些琐碎的宏定义,在项目中任何地方都可以引用,加快了编译的速度 Xcode6之后的版本都是需要 ...

  8. Vijos P1521 跳舞 贪心

    本来想找一道网络流的题来着,结果这道题越看越不对劲,总觉得这题存在不用网络流的解法 看了题解区以后坚定了自己的猜想 #include <cstdio> #include <cstri ...

  9. jQuery慢慢啃之核心(一)

    1. $("div > p"); div 元素的所有p子元素. $(document.body).css( "background", "bla ...

  10. 利用js获取时间并输出值

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...