【题目】

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
代码如下:
 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define Maxn 1010 struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
}; typedef Point Vector;
Point p[Maxn]; int n,l;
const double pi=3.1415926535898; double myabs(double x) {return x<?-x:x;} const double eps=1e-;
int dcmp(double x)//判断正负和零
{
if(myabs(x)<eps) return ;
else return x<?-:;
}
Vector operator - (Point A,Point B) {return Vector(A.x-B.x,A.y-B.y);} double Dot(Vector A,Vector B) {return A.x*B.x+A.y*B.y;}
double Cross(Vector A,Vector B) {return A.x*B.y-A.y*B.x;}
double Length(Vector A) {return sqrt(Dot(A,A));} bool cmp(Point x,Point y) {return dcmp(x.x-y.x)==?(x.y<y.y):(x.x<y.x);}
Point ch[Maxn];int len=; void covexhull()
{
for(int i=;i<=n;i++)
{
while(len>&&Cross(ch[len]-ch[len-],p[i]-ch[len-])<=) len--;
ch[++len]=p[i];
}int k=len;
for(int i=n-;i>=;i--)
{
while(len>k&&Cross(ch[len]-ch[len-],p[i]-ch[len-])<=) len--;
ch[++len]=p[i];
}
if(n>) len--;
} double PolygonLength()
{
double L=;
for(int i=;i<=len;i++)
L+=Length(ch[i]-ch[i-]);
L+=Length(ch[]-ch[len]);
return L;
} int main()
{
scanf("%d%d",&n,&l);
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
sort(p+,p++n,cmp);
covexhull();
printf("%.0f\n",PolygonLength()+pi*l*);
return ;
}

[POJ1113]


2016-04-28 19:32:02


												

【POJ1113】Wall(凸包)的更多相关文章

  1. POJ1113 Wall —— 凸包

    题目链接:https://vjudge.net/problem/POJ-1113 Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

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

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

  3. POJ1113:Wall (凸包:求最小的多边形,到所有点的距离大于大于L)

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

  4. POJ1113 Wall 凸包

    题目大意:建立围墙将城堡围起来,要求围墙至少距离城堡L,拐角处用圆弧取代,求围墙的长度. 题目思路:围墙长度=凸包周长+(2*PI*L),另外不知道为什么C++poj会RE,G++就没问题. #inc ...

  5. POJ1113 Wall

    题目来源:http://poj.org/problem?id=1113题目大意: 如图所示,给定N个顶点构成的一个多边形和一个距离值L.建立一个围墙,把这个多边形完全包含在内,且围墙距离多边形任一点的 ...

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

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

  7. POJ-1113 Wall 计算几何 求凸包

    题目链接:https://cn.vjudge.net/problem/POJ-1113 题意 给一些点,求一个能够包围所有点且每个点到边界的距离不下于L的周长最小图形的周长 思路 求得凸包的周长,再加 ...

  8. POJ1113 Wall【凸包】

    题意: 求把城堡围起来需要的最小墙壁周长. 思路: 围墙周长为=n条平行于凸包的线段+n条圆弧的长度=凸包周长+围墙离城堡距离L为半径的圆周长. 代码: ...还是看大佬写的,自己做个记录方便日后复习 ...

  9. POJ 1113 - Wall 凸包

    此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...

  10. hdu 1348 Wall (凸包)

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

随机推荐

  1. atlassian-jira-confluence-bitbucket破解

    ==================================================================================================== ...

  2. android线程与线程池-----线程池(二)《android开发艺术与探索》

    android 中的线程池 线程池的优点: 1 重用线程池中的线程,避免了线程的创建和销毁带来的性能开销 2 能有效的控制最大并发数,避免大量线程之间因为喜欢抢资源而导致阻塞 3 能够对线程进行简单的 ...

  3. Bash判断是否是root

    #!/bin/bash ]; then echo "Not Root" exit fi

  4. SQL带参数拼接

    List<SqlParameter> paras = new List<SqlParameter>(); string wherSql = PreWhereSQL + GetQ ...

  5. Linux同步时间命令ntpdate

    转自:http://orgcent.com/linux-ntpdate/ 由于要同步Linux服务器的时间,为了保证时间的高度准确性,放弃date命令而转向ntpdate(同步时间命令). 方案如下: ...

  6. WebService学习笔记

    WebService有什么用? 入门之前先简单介绍下WCF.在用WebService做开发时,很多人都不知道WCF和WebService之间的关系.实际上WCF包含了WebService,这是一个很强 ...

  7. DataGridView 绑定 List

    DataGridView 绑定 List<T> 不会自动更新 正确方式是将  List<T> 设置为 BindingList<T> 即可 (双向绑定)

  8. BigDecimal类型的详情

    一.简介 1.概述 BigDecimal由任意精度的整数非标度值和32位的整数标度(scale)组成.如果为零或正数,则标度是小数点后的位数.如果为负数,则将该数的非标度值乘以10的负scale次幂. ...

  9. Objective c 自动释放池

    学IOS 的大家都知道,IOS 一共有三种内存管理方式:MRC .ARC.自动释放池.我按照我个人的理解简述一下自动释放池,希望能给大家一点帮助,如有错误请大家及时批评指正. 自动释放池有几个特点:1 ...

  10. Java程序实现导出Excel,支持IE低版本

    来博客园两年多了,最近才开通了微博,因为懒所以也一直没有写东西,今天想整理一下自己前段时间遇到的一个导出的问题. 因为项目的需求,要做一部分导出功能.开始的时候用的公司的导出,但是很奇怪有部分模块导出 ...