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


Sample Output


Hint

结果四舍五入就可以了

Solution

凸包模板题,这里用水平序+上下凸壳求图包

orz clover_hxy

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 3010
#define Eps 1e-18
#define Pi 3.1415926535 using namespace std; struct Vctor{
double x, y; Vctor() {} Vctor(double _x, double _y) : x(_x), y(_y) {} bool operator == (const Vctor b)const {return x == b.x && y == b.y;} bool operator < (const Vctor b)const {return x < b.x || (x == b.x && y < b.y);}
} d[MAXN], _pb[MAXN], e[MAXN]; Vctor operator + (Vctor a, Vctor b) {return Vctor(a.x + b.x, a.y + b.y);} Vctor operator - (Vctor a, Vctor b) {return Vctor(a.x - b.x, a.y - b.y);} Vctor operator * (Vctor a, double b) {return Vctor(a.x * b, a.y * b);} Vctor operator / (Vctor a, double b) {return Vctor(a.x / b, a.y / b);} double Dot(Vctor a, Vctor b) {return a.x * b.x + a.y * b.y;} double Cro(Vctor a, Vctor b) {return a.x * b.y - a.y * b.x;} int Cmp(double x){
if(fabs(x) < Eps)return ;
return x < ? - : ;
} double Dis(Vctor a) {return sqrt(Dot(a, a));} double ans;
int n, L, top; void Samsara(){
sort(d, d + n);
int k;
for(int i = ; i < n; i++){
while(top > && Cmp(Cro(_pb[top - ] - _pb[top - ], d[i] - _pb[top - ])) <= )top--;
_pb[top++] = d[i];
}
k = top;
for(int i = n - ; i >= ; i--){
while(top > k && Cmp(Cro(_pb[top - ] - _pb[top - ], d[i] - _pb[top - ])) <= )top--;
_pb[top++] = d[i];
}
if(n > )top--;
} int main(){
scanf("%d%d", &n, &L);
for(int i = ; i < n; i++)
scanf("%lf%lf", &d[i].x, &d[i].y);
Samsara();
for(int i = ; i <= top; i++)
e[i] = _pb[i] - _pb[i - ];
e[top + ] = _pb[] - _pb[top];
for(int i = ; i <= top + ; i++)
ans += Dis(e[i]);
ans += Pi * L * ;
printf("%.0lf\n", ans);
return ;
}

[poj1113][Wall] (水平序+graham算法 求凸包)的更多相关文章

  1. nyoj-78-圈水池(Graham算法求凸包)

    题目链接 /* Name:nyoj-78-圈水池 Copyright: Author: Date: 2018/4/27 9:52:48 Description: Graham求凸包 zyj大佬的模板, ...

  2. POJ 2187 旋转卡壳 + 水平序 Graham 扫描算法 + 运算符重载

    水平序 Graham 扫描算法: 计算二维凸包的时候可以用到,Graham 扫描算法有水平序和极角序两种. 极角序算法能一次确定整个凸包, 但是计算极角需要用到三角函数,速度较慢,精度较差,特殊情况较 ...

  3. (模板)poj1113(graham扫描法求凸包)

    题目链接:https://vjudge.net/problem/POJ-1113 题意:简化下题意即求凸包的周长+2×PI×r. 思路:用graham求凸包,模板是kuangbin的. AC code ...

  4. (模板)graham扫描法、andrew算法求凸包

    凸包算法讲解:Click Here 题目链接:https://vjudge.net/problem/POJ-1113 题意:简化下题意即求凸包的周长+2×PI×r. 思路:用graham求凸包,模板是 ...

  5. 关于graham扫描法求凸包的小记

    1.首先,凸包是啥: 若是在二维平面上,则一般的,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有的点. ───────────────────────────── ...

  6. Graham扫描法 --求凸包

    前言: 首先,什么是凸包? 假设平面上有p0~p12共13个点,过某些点作一个多边形,使这个多边形能把所有点都“包”起来.当这个多边形是凸多边形的时候,我们就叫它“凸包”.如下图:  然后,什么是凸包 ...

  7. LA 4728 旋转卡壳算法求凸包的最大直径

    #include<iostream> #include<cstdio> #include<cmath> #include<vector> #includ ...

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

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

  9. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

随机推荐

  1. mysql数据库开发常见问题及优化

    mysql 数据库是被广泛应用的关系型数据库,其体积小.支持多处理器.开源并免费的特性使其在 Internet 中小型网站中的使用率尤其高.在使用 mysql 的过程中不规范的 SQL 编写.非最优的 ...

  2. 浅析MySQL复制

    MySQL的复制是基于binlog来实现的. 流程如下 涉及到三个线程,主库的DUMP线程,从库的IO线程和SQL线程. 1. 主库将所有操作都记录到binlog中.当复制开启时,主库的DUMP线程根 ...

  3. 多线程条件通行工具——Semaphore

    Semaphore的作用是,限制线程通行的数量,如果线程进入时达到通行数量,便等待其它正在通行的线程释放. acquire()获取通行 release()释放通行 availablePermits() ...

  4. 真实记录疑似Linux病毒导致服务器 带宽跑满的解决过程

    案例描述 由于最近我在重构之前的APP,需要和server端进行数据交互,发现有一个现象,那么就是隔1~2天总会发生获取数据超时的问题,而且必须要重启服务器才能解决.早在之前,我有留意到这个问题,但是 ...

  5. 两种方式实现java生成Excel

    Web应用中难免会遇到需要将数据导出并生成excel文件的需求.同样,对于本博客中的总结,也是建立在为了完成这样的一个需求,才开始去了解其实现形式,并且顺利完成需求的开发,先将实现过程总结于此.本博文 ...

  6. 用Github pages搭建自己制作的网页,方法最简单,适用于新手

    本文固定链接http://blog.csdn.net/pspgbhu/article/details/51205264 本人自学前端一个多月,写个几个网页想要用来应聘,网上搜各种搭建网站的方法,发现不 ...

  7. ASP.NET Core 中文文档 第三章 原理(13)管理应用程序状态

    原文:Managing Application State 作者:Steve Smith 翻译:姚阿勇(Dr.Yao) 校对:高嵩 在 ASP.NET Core 中,有多种途径可以对应用程序的状态进行 ...

  8. AngularJS中get请求URL出现跨域问题

    今天早上帮助同学看了一个AngularJS的问题,主要是请求中出现了跨域访问,请求被阻止. 下面是她给我的代码: <html lang="en" ng-app="m ...

  9. .NET 同步与异步之封装成Task(五)

    本随笔续接:.NET 实现并行的几种方式(四) 前篇随笔已经介绍了几种可以实现并发的方式,其中异步方法.是最简便的方式.而 异步方式是基于 Task 和 async修饰符和await运算符实现的. 换 ...

  10. .NET 实现并行的几种方式(三)

    本随笔续接:.NET 实现并行的几种方式(二) 在前两篇随笔中,先后介绍了 Thread .ThreadPool .IAsyncResult (即 APM系列) .Task .TPL (Task Pa ...