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

Sample Input

Sample Output

题意:

  要将所有点围成一个类似于矩形的形状,角变成弧。

  也就是求凸包周长+一个完整的圆周长。

  因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆。

  剩余的部分就是凸包的周长。

  具体如下图。

思路:

  先求出凸包,然后求一个周长。注意四舍五入!!!

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define PI 3.1415926535
using namespace std;
struct node
{
int x,y;
};
node vex[];//存入的所有的点
node stackk[];//凸包中所有的点
bool cmp1(node a,node b)
{
if(a.y==b.y)
return a.x<b.x;
else
return a.y<b.y;
}
int cross(node a,node b,node c)//计算叉积
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
double dis(node a,node b)//计算距离
{
return sqrt((a.x-b.x)*(a.x-b.x)*1.0+(a.y-b.y)*(a.y-b.y));
}
bool cmp(node a,node b)//极角排序
{
int m=cross(vex[],a,b);
if(m==)
return dis(vex[],a)-dis(vex[],b)<=?true:false;
else
return m>?true:false;
}
int main()
{
int t,L;
while(~scanf("%d%d",&t,&L))
{
int i;
for(i=; i<t; i++)
{
scanf("%d%d",&vex[i].x,&vex[i].y);
}
if(t==)
printf("%.2f\n",0.00);
else if(t==)
printf("%.2f\n",dis(vex[],vex[]));
else
{
sort(vex,vex+t,cmp1);
sort(vex+,vex+t,cmp);
memset(stackk,,sizeof(stackk));
stackk[]=vex[];
stackk[]=vex[];
int top=;//最后凸包中拥有点的个数
for(i=; i<t; i++)
{
while(i>=&&cross(stackk[top-],stackk[top],vex[i])<)
top--;
stackk[++top]=vex[i];
}
double s=;//注意精度
for(i=; i<=top; i++)
s+=dis(stackk[i-],stackk[i]);
s+=dis(stackk[top],vex[]);
s+=*PI*L;
int ans=s+0.5;//四舍五入
printf("%d\n",ans);
}
}
}

POJ 1113 Wall (凸包)的更多相关文章

  1. POJ 1113 Wall 凸包 裸

    LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...

  2. poj 1113 Wall 凸包的应用

    题目链接:poj 1113   单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...

  3. POJ 1113 Wall 凸包求周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26286   Accepted: 8760 Description ...

  4. POJ 1113 - Wall 凸包

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

  5. poj 1113 wall(凸包裸题)(记住求线段距离的时候是点积,点积是cos)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43274   Accepted: 14716 Descriptio ...

  6. POJ 1113 Wall【凸包周长】

    题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  7. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  8. POJ 1113 Wall(凸包)

    [题目链接] http://poj.org/problem?id=1113 [题目大意] 给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度 [题解] 画图易得答案为凸包的 ...

  9. POJ 1113 Wall 求凸包

    http://poj.org/problem?id=1113 不多说...凸包网上解法很多,这个是用graham的极角排序,也就是算导上的那个解法 其实其他方法随便乱搞都行...我只是测一下模板... ...

  10. POJ 1113 Wall 求凸包的两种方法

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31199   Accepted: 10521 Descriptio ...

随机推荐

  1. vue全家桶(Vue+Vue-router+Vuex+axios)(Vue+webpack项目实战系列之二)

    Vue有多优秀搭配全家桶做项目有多好之类的咱就不谈了,直奔主题. 一.Vue 系列一已经用vue-cli搭建了Vue项目,此处就不赘述了. 二.Vue-router Vue的路由,先献上文档(http ...

  2. 映射语句之INSERT语句

    1.一个 INSERT SQL 语句可以在<insert>元素在映射器 XML 配置文件中配置 例子: <insert id="insertStudentWithId&qu ...

  3. CYQ.Data V5 分布式自动化缓存设计介绍(二)

    前言: 最近一段时间,开始了<IT连>创业,所以精力和写的文章多数是在分享创业的过程. 而关于本人三大框架CYQ.Data.Aries.Taurus.MVC的相关文章,基本都很少写了. 但 ...

  4. windows安装nvm管理node版本

    1.卸载原本系统里面的nodejs 2.下载nvm安装包:https://github.com/coreybutler/nvm-windows/releases ---->nvm-setup.z ...

  5. 简单的视频采集demo

    打算做个简单的聊天软件,其中一个我没做过的,就是视频采集. 在网上查了许久资料,终于搞清楚了dshow采集视频的流程 参考资料如下: https://msdn.microsoft.com/en-us/ ...

  6. 4.jsp的内置对象

    1.jsp有九大内置对象 out request response session application page pagecontext exception config 2.用户发请求 requ ...

  7. 解决VMware虚拟机不能上网的问题

    这是其中一种情况,因为使用360等加速的时候把VMware 的DHCP等服务关闭了,重新启动服务即可,方法是WIN+R 输入cmd,在doc输入services.ms打开服务,找到 把这些都启动即可

  8. Thrift总结(二)创建RPC服务

    前面介绍了thrift 基础的东西,怎么写thrift 语法规范编写脚本,如何生成相关的语言的接口.不清楚的可以看这个<Thrift总结(一)介绍>.做好之前的准备工作以后,下面就开始如何 ...

  9. H3CNE实验:配置基于端口划分的VLAN及Trunk

    配置准备数据 | 设备名称 | IP地址 | VLAN网关 | 接口 | VLAN | |--------------|------------|-------------|----------|-- ...

  10. Python 操作 MYSQL

    本文介绍了 Python 操作 MYSQL.执行 SQL 语句.获取结果集.遍历结果集.取得某个字 段.获取表字段名.将图片插入数据库.执行事务等各种代码实例和详细介绍,代码居多, 是一桌丰盛唯美的代 ...