Wall

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,所以一个多边形的所顶点对应弧长相加其实就是一个圆。
所以,最后总长为 凸包边长+π*2*l
最后需要的就是输出:

这里写代码片
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>using namespace std;const double eps=1e-8;
const double PI=acos(-1.0);
const int N=10100;
struct node{double x,y;node (double xx=0,double yy=0){x=xx;y=yy;}
};
node po[N];
double l;
int n,top,sta[N*2];node operator -(const node &a,const node &b)
{return node(a.x-b.x,a.y-b.y);
}int dcmp(double x)
{if (fabs(x)<eps) return 0;else if (x<0) return -1;else return 1;
}int cmp(const node &a,const node &b)
{if (dcmp(a.x-b.x)!=0) return a.x<b.x;else return a.y<b.y;
}double Cross(node a,node b)
{return a.x*b.y-a.y*b.x;
}double dis(node a,node b)
{return (double)sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}void TuB()  //水平排序的凸包,实现起来简单
{top=0;memset(sta,0,sizeof(sta));int i;for (i=1;i<=n;i++){while (top>1&&dcmp(Cross(po[i]-po[sta[top-1]],po[sta[top]]-po[sta[top-1]]))<=0) top--;sta[++top]=i;}int k=top;for (i=n-1;i>=1;i--){while (top>k&&dcmp(Cross(po[i]-po[sta[top-1]],po[sta[top]]-po[sta[top-1]]))<=0) top--;sta[++top]=i; }if (n>1) top--;  //n>1double ans=0;ans+=dis(po[sta[1]],po[sta[top]]);while (top>1) ans+=dis(po[sta[top]],po[sta[top-1]]),top--;ans+=(double)l*2*PI; //if(ans-(int)ans >= 0.5)printf("%d\n",(int)ans+1);elseprintf("%d\n",(int)ans);return;
}int main()
{scanf("%d%lf",&n,&l);for (int i=1;i<=n;i++)scanf("%lf%lf",&po[i].x,&po[i].y);sort(po+1,po+1+n,cmp);TuB();return 0;
}

转载于:https://www.cnblogs.com/wutongtong3117/p/7673613.html

poj1113/hdu1348(凸包。。。两个网站上的输入输出有点出入)相关推荐

  1. 8305天距离梦想还有8,352 千米 2012-03-31 23:18:53 柏林勃兰登堡门 再过两天就是我22周岁生日了,我在生命网站上摁下自己的出生年月,上面显示我已经度过了8305天,走

    8305天距离梦想还有8,352 千米   http://www.douban.com/note/207745712/ 2012-03-31 23:18:53 柏林勃兰登堡门 再过两天就是我22周岁生 ...

  2. phpstudy一个域名配置两个网站(一个是thinkphp5,一个是原生php)

    phpstudy一个域名配置两个网站(一个是thinkphp5,一个是原生php) 一.总结 一句话总结:把原生php的网站直接放到thinkphp5的public目录下可以解决以stem.aaaa. ...

  3. 两个网站做到同一个服务器,两个网站放在同一个服务器 备案

    两个网站放在同一个服务器 备案 内容精选 换一换 没有,华为云包含企业邮箱服务,具体请参考: https://www.huaweicloud.com/marketplace/activity/mail ...

  4. 你社交网站上的照片,也许已经被用来训练人工智能了

    来源:网易智能 斯特于2013年拍摄的这张照片被收录在IBM的人像数据集(Diversity in Faces)中 毫无疑问,这张家庭照片是非常可爱的:照片中的爸爸留着短须,戴着无框眼镜,棕色头发的妈 ...

  5. ECJia如何配置两个网站访问共同的数据库和附件资源

    一.问题起源 ECJia到家是一款开源的O2O电商系统.在我们使用的时候,会经常遇到官方新版本升级,这时,我们又想保持当前站点的稳定运行,又想升级到新版本体验功能.我们就需要再搭建一个升级测试站点,这 ...

  6. idea重要插件代码颜色_颜色在您的网站上的重要性和品牌形象

    idea重要插件代码颜色 Choosing the right colors for a website or a logo can be a perplexing and time-consumin ...

  7. 网站搜索功能怎么实现_电商网站上的搜索功能是如何实现的?

    今天是刘小爱自学Java的第159天. 感谢你的观看,谢谢你. 学习计划安排如下: 索引库本质上和数据库类似,也是存储数据的,既然如此自然也会有增删改查. 那么这个索引库到底有何特别应用呢? 索引库的 ...

  8. php 网站上传大小限制吗,配置PHP程序网站上传文件大小的限制!

    PHP程序做的网站,上传文件大小的限制,是在PHP的配置文件中设置的. WORDPRESS网站也是PHP程序,我们会在WordPress里面的很多地方遇到文件上传大小的限制,比如在媒体库里面,上传图片 ...

  9. 【网站】一个空间放两个网站,且不用子目录绑定域名的方法

    一个空间绑定两个域名的办法操作 很多空间支持多域名绑定,但是不支持子目录绑定,这时我们就可以考虑如下几种方法来实现一个空间放多个域名站点的方法,只是其他站点都需要在一个目录下大开,但这毫不影响搜索引擎 ...

最新文章

  1. 也许,这样理解 HTTPS 更容易!
  2. 运行配置文件中指定类的指定方法
  3. Rhel7 设置目录权限,acl权限
  4. 2014中国软件开发者调查
  5. C#5 复习总结循环 迭代和穷举
  6. window平台编译draco库
  7. jquery 菜鸟教程
  8. 耶鲁大学开放课程:《金融市场》第3课
  9. 十六宫格拼图(A*/IDA*)(曼哈顿距离)
  10. 下载Gazebo模型
  11. PMBOK(项目管理实践指南)绝不是PMP考试的指定教材,看完你就知道
  12. python循环引用的解决办法
  13. 首款Intel双核挑衅四核 联想K900评测
  14. Redis和RedisClient 官网下载方式
  15. Linux下安装python集成开发环境——Ulipad
  16. 一文读懂群延时(Group Delay):非常简单易懂
  17. 计算机管理里面更改驱动器,win10系统更改和删除驱动器号的处理技巧
  18. STVP STM8 COSMIC C编译器在WIN10上的安装使用( can‘t access configuration database 问题解决方法)
  19. Basler pylon-ros-camera驱动 Xavier AGX调试记录 (Arm架构)
  20. 【数据分析】移动互联网运营推广专业名词大全(in)

热门文章

  1. 关于把字符串整数转换成整数的程序
  2. cisco路由器故障判断及排除 计算机管理与维护
  3. [美丽的烦恼] SQL删除某些字段重复的记录(只保留一条)
  4. HttpWebRequest自动登录网站并获取网站内容(不包含验证码的网站)
  5. ICCV2021 香港理工、阿里达摩院提出RealVSR:视频超分任务中的新数据集与损失方案...
  6. ECCV 2020 论文大盘点-人员重识别(ReID)篇
  7. 如何学习机器学习、看待算法竞赛?粉丝精选留言
  8. 最新综述|深度学习的单目人体姿态估计
  9. 让目标检测和实例分割互相帮助,地平线实习生论文被AAAI 2020收录
  10. 2021年,作为算法工程师的你们会在CV业务上用Transformer吗?