Wall

[题目链接](http://poj.org/problem?id=1113 题目链接在这里").

Time Limit: 1000MS Memory Limit: 10000K

Total Submissions: 42823 Accepted: 14602

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

Hint

结果四舍五入就可以了

题意:

求凸包周长再加上一个半径为L的圆的周长

代码:

#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <set>
#include <vector>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <climits>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
#define inf 0x3f3f3f3f
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MAXN = 1e4 + 7;
const ll MAXM = 1e3 + 7;
const ll MOD = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
PDD a[MAXN], sta[MAXN];
int cnt = 0;
bool ccw(PDD a, PDD b, PDD c) //利用叉积判断方向(c点是否在ab向量的逆时针方向)
{
return (b.first - a.first) * (c.second - a.second) - (b.second - a.second) * (c.first - a.first) > 0;
/* 大于0说明逆时针方向 */
/* >=则顺便删下共线 */
}
void convex(int n, PDD a[])
{
sort(a, a + n);
cnt = 0;
for (int i = 0; i < n; i++) //计算上半个凸包
{
/*如果点数有两个或以上且即将加入凸包的点位于凸包倒数第二点和倒数第一个点所构成的向量的逆时针位置,则删除倒数第一个点*/
while (cnt > 1 && ccw(sta[cnt - 2], sta[cnt - 1], a[i]))
--cnt;
sta[cnt++] = a[i];
}
int k = cnt;
for (int i = n - 2; i >= 0; --i) //计算下半个凸包
{
while (cnt > k && ccw(sta[cnt - 2], sta[cnt - 1], a[i]))
--cnt;
sta[cnt++] = a[i];
}
if (n > 1) //对于只有一个点的包再单独判断
--cnt;
}
double dis(PDD x, PDD y)
{
return sqrt((y.second - x.second) * (y.second - x.second) + (y.first - x.first) * (y.first - x.first));
}
int main()
{
int N, L;
while (~scanf("%d%d", &N, &L))
{
for (int i = 0; i < N; i++)
scanf("%lf%lf", &a[i].first, &a[i].second);
convex(N, a);
double ans = 2 * pi * L;
for (int i = 1; i < cnt; i++)
ans += dis(sta[i], sta[i - 1]);
ans += dis(sta[0], sta[cnt - 1]);
printf("%d\n", (int)(ans + 0.5));
}
return 0;
}

pku1113-Wall 凸包(安德鲁算法版)的更多相关文章

  1. POJ 1113 Wall 凸包求周长

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

  2. hdu 1348 Wall (凸包)

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

  3. POJ1113 Wall —— 凸包

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

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

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

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

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

  6. POJ 1113 - Wall 凸包

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

  7. Wall(凸包POJ 1113)

    Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32360 Accepted: 10969 Description On ...

  8. POJ1113 Wall 凸包

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

  9. HDU1348 Wall 凸包

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1348 题意:给出一个凸包,求出与凸包距离 L的外圈周长 凸包模板题,练练Andrew算法求出凸包周长再 ...

随机推荐

  1. 阿里面试官让我讲讲Unicode,我讲了3秒说没了,面试官说你可真菜

    本文首发于微信公众号:程序员乔戈里 乔哥:首先说说什么是Unicode.码点吧~要想搞懂,这些概念必须清楚 什么是Unicode? 下图来自http://www.unicode.org/standar ...

  2. 机器学习回顾篇(14):主成分分析法(PCA)

    .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...

  3. Date、Time类型拼接成字符串

    Date.Time类型拼接成字符串 语言用的是kotlin,和Java类似 var time = "" val sdf1 = SimpleDateFormat("yyyy ...

  4. 【转】VS2017缺少文件

    在VS工程中,添加c/c++工程中外部头文件及库的基本步骤: 1.添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录:加上头文件存放目录. 2.添加文件引用 ...

  5. c++ beep 演奏一次质量不高的天空之城

    beep函数用法: beep(HZ,time); hz是发出多少赫兹声音,time是发声时间(ms) 话不多说,上代码 #include <cstdio> #include <win ...

  6. 通过例子进阶学习C++(五)计算2的1次方至2的64次方之和

    本文是通过例子学习C++的第五篇,通过这个例子可以快速入门c++相关的语法. 1.上篇回顾 在上一篇中,我们通过字符数组计算264次方: 通过例子进阶学习C++(四)计算2的64次方 带着这个问题:为 ...

  7. CSP-S rp++

    心无旁骛 认真思考 努力骗分(哈哈) I Love CSP! 反正像我这种大菜鸟也考不了多少 尽力打 本次考试期望 day1 100 70-100 30-? day2 100 ? ? 总:300-? ...

  8. cogs 2. 旅行计划 dijkstra+打印路径小技巧

    2. 旅行计划 ★★   输入文件:djs.in   输出文件:djs.out   简单对比时间限制:3 s   内存限制:128 MB [题目描述] 过暑假了,阿杜准备出行旅游,他已经查到了某些城市 ...

  9. cogs 1176. [郑州101中学] 月考 Set 做法

    1176. [郑州101中学] 月考 ★★☆   输入文件:mtest.in   输出文件:mtest.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 在上次的月考中B ...

  10. TypeScript 源码详细解读(3)词法2-标记解析

    在上一节主要介绍了单个字符的处理,现在我们已经有了对单个字符分析的能力,比如: 判断字符是否是换行符:isLineBreak 判断字符是否是空格:isWhiteSpaceSingleLine 判断字符 ...