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. About Me - 关于

    0x00 简介 97年生 计算机相关专业,无线电安全攻防方向. 涉猎较多,喜欢研究无线.硬件.软件.网络.攻击.检测.防御等各类安全技术 精通较少,主要擅长的还是硬件.渗透.无线攻击方面. 现阶段在研 ...

  2. 利用MFC Picture Control控件 加载bmp,png

    1.在资源视图,选择PictureControl,并且在属性中把Type设置为Bitmap. 2.加载PNG CStatic* pWnd = (CStatic*)GetDlgItem(IDC_PIC) ...

  3. 在JSP中使用formatNumber控制要显示的小数位数

    先引入标签库 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 比 ...

  4. Linux sed命令用法

    概述 sed命令是一个面向字符流的非交互式编辑器,不允许用户与它进行交互操作.sed是以行为单位处理文本内容的.在shell中,可以批量修改文本内容. 用法 sed [选项] [动作] 选项与参数:- ...

  5. thinkphp5配置讲解

    一.thinkphp配置类型有哪些? 1.在thinkphp中,有6种配置.即惯例配置,应用配置.扩展配置.模块配置.场景配置.动态配置. 2.惯例配置就是系统默认的配置. 3.应用配置就是我们自己开 ...

  6. CentOS7 LNMP+phpmyadmin环境搭建(一、虚拟机及centos7安装)

    前一阵子配公司的服务器的时候,发现网上好多教程杂乱无章,然后便根据网上已有资料自己整理了一个lnmp环境的安装教程.因为懒,已经好久没写过博客了.趁着这次公司招新人,把之前整理的文档又整理了一次,顺便 ...

  7. 基于Geomesa服务查询轨迹数据无法根据空间和时间范围进行结果查询

    一.Geomesa - QuickStart(教程工程包)   百度网盘下载地址:geomesa-tutorials-master.7z 二.解压后,IDEA编译如下 百度网盘下载地址:IDEA201 ...

  8. 『Python基础-11』集合 (set)

    # 『Python基础-11』集合 (set) 目录: 集合的基本知识 集合的创建 访问集合里的值 向集合set增加元素 移除集合中的元素 集合set的运算 1. 集合的基本知识 集合(set)是一个 ...

  9. Python学习手册之元组拆包、三元运算符和 else 语句深入

    在上一篇文章中,我们介绍了 Python 之禅. Python 编程规范和函数参数,现在我们介绍 Python 的元组拆包.三元运算符和对 Python 的 else 语句深入讲解.查看上一篇文章请点 ...

  10. rails ajax上传文件以及controller处理

    ajax提交文件 var formData = new FormData(); formData.append('file', $('input[name="file"]')[0] ...