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.

 
题目大意:要在一城堡外建一围墙,要求围墙与城堡的距离不能小于L,求围墙最小长度
思路:求城堡凸包(完全没看出哪里要求围墙不能凹了……),再加上2*PI*L就是答案,围墙曲线的总长度就是2*PI*L
 
Graham-Scan算法求凸包,不排极角的方法(防误差),32MS
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm> struct POINT {
int x, y;
POINT(int xx = 0, int yy = 0): x(xx), y(yy) {}
}; const int MAXN = 1010;
const double PI = acos(-1.0); int n, L;
int stk[MAXN], top;
POINT p[MAXN]; inline bool cmp(const POINT &a, const POINT &b) {
if(a.y == b.y) return a.x < b.x;
return a.y < b.y;
}
//turn left
inline bool Cross(POINT &sp, POINT &ep, POINT &op) {
return (sp.x - op.x) * (ep.y - op.y) - (ep.x - op.x) * (sp.y - op.y) >= 0;
} inline double dist(POINT &a, POINT &b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
} void Graham_scan() {
std::sort(p, p + n, cmp);
top = 1;
stk[0] = 0; stk[1] = 1;
for(int i = 2; i < n; ++i) {
while(top && Cross(p[i], p[stk[top]], p[stk[top - 1]])) --top;
stk[++top] = i;
}
int len = top;
stk[++top] = n - 2;
for(int i = n - 3; i >= 0; --i) {
while(top != len && Cross(p[i], p[stk[top]], p[stk[top - 1]])) --top;
stk[++top] = i;
}
} void solve() {
double ans = L * PI * 2;
stk[++top] = stk[0];
for(int i = 0; i < top; ++i)
ans += dist(p[stk[i]], p[stk[i+1]]);
printf("%.0f\n", ans);
} int main() {
while(scanf("%d%d", &n, &L) != EOF) {
for(int i = 0; i < n; ++i) scanf("%d%d", &p[i].x, &p[i].y);
Graham_scan();
solve();
}
}

  

POJ 1113 Wall(计算几何の凸包)的更多相关文章

  1. POJ 1113 Wall【凸包周长】

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

  2. 2018.07.04 POJ 1113 Wall(凸包)

    Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...

  3. POJ 1113 Wall(凸包)

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

  4. POJ 1113 Wall 求凸包

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

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

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

  6. POJ 1113 Wall (凸包)

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

  7. 题解报告:poj 1113 Wall(凸包)

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

  8. poj 1113 Wall 凸包的应用

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

  9. 【POJ】1113 Wall(凸包)

    http://poj.org/problem?id=1113 答案是凸包周长+半径为l的圆的周长... 证明?这是个坑.. #include <cstdio> #include <c ...

随机推荐

  1. CF1066B Heaters(贪心)

    题意描述: Vova先生的家可以看作一个n×1的矩形,寒冷的冬天来了,Vova先生想让他的家里变得暖和起来.现在我们给你Vova先生家的平面图,其中111表示这个地方是加热炉,0表示这个地方什么也没有 ...

  2. Ubuntu下Zabbix结合percona监控mysql数据

    按道理来说zabbix就自带的MySQL插件来监控mysql数据库,但是你会发现,自带的mysql监控项是很少的,根本满足不了公司的需求.由于它本身自带的模板太过简单了,所以需要做更详细的监控,而pe ...

  3. Vue清除所有JS定时器

    Vue清除所有JS定时器 在webpack + vue 的项目中如何在页面跳转的时候清除所有的定时器 JS定时器会有一个返回值(数字),通过这个返回值我们可以找到这个定时器 在vue项目中可以使用路由 ...

  4. js实现所有异步请求全部加载完毕后,loading效果消失

    在实际开发中,一定有情况是这样的,一个页面我们有多个地方请求了ajax,在这种情况下,我们要实现数据没来之前出现我们炫酷的loading效果,而且要等到所有的ajax都请求完毕后,才让我们的loadi ...

  5. php函数strtotime结合date时间修饰语的使用

    下面简单介绍在项目开发中date时间函数和strtotime所遇到的问题,以及解决办法. 原文地址:小时刻个人技术博客 > http://small.aiweimeng.top/index.ph ...

  6. 微信小程序快速转成百度小程序的方法

    1.安装Node.js(>8.5.0)https://nodejs.org/ npm升级到最新版本的方法:npm install -g npm自动更新到最新版本 2.配置cnpm:在命令行中输入 ...

  7. pyhton实现简单的木马程序

    十一的晚上,平时都在写工作的代码,好久没有专门看一些知识了,感觉想刚开始学c一样,搞到半夜 还是<python网络编程基础>,写了小脚本,没有任何结构,一句一句的往下写的,反正是可以实现想 ...

  8. python3 练习题100例 (二)

    题目二:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%:20万到40万 ...

  9. vue cli3超详细创建多页面配置

    1.首先按照vue cli3 给的入门文档下载个vue cli3 如果之前下载了vue cli2的要先卸载之前的 2.检查安装是否成功 3.ok,现在环境搭建好了,新建项目 vue create he ...

  10. 使用AutoFac实现依赖注入(封装一个注册类)

    public class AutoFacBootStrapper { public static void CoreAutoFacInit() { var builder = new Containe ...