[poj1113][Wall] (水平序+graham算法 求凸包)
Description
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
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
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算法 求凸包)的更多相关文章
- nyoj-78-圈水池(Graham算法求凸包)
题目链接 /* Name:nyoj-78-圈水池 Copyright: Author: Date: 2018/4/27 9:52:48 Description: Graham求凸包 zyj大佬的模板, ...
- POJ 2187 旋转卡壳 + 水平序 Graham 扫描算法 + 运算符重载
水平序 Graham 扫描算法: 计算二维凸包的时候可以用到,Graham 扫描算法有水平序和极角序两种. 极角序算法能一次确定整个凸包, 但是计算极角需要用到三角函数,速度较慢,精度较差,特殊情况较 ...
- (模板)poj1113(graham扫描法求凸包)
题目链接:https://vjudge.net/problem/POJ-1113 题意:简化下题意即求凸包的周长+2×PI×r. 思路:用graham求凸包,模板是kuangbin的. AC code ...
- (模板)graham扫描法、andrew算法求凸包
凸包算法讲解:Click Here 题目链接:https://vjudge.net/problem/POJ-1113 题意:简化下题意即求凸包的周长+2×PI×r. 思路:用graham求凸包,模板是 ...
- 关于graham扫描法求凸包的小记
1.首先,凸包是啥: 若是在二维平面上,则一般的,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有的点. ───────────────────────────── ...
- Graham扫描法 --求凸包
前言: 首先,什么是凸包? 假设平面上有p0~p12共13个点,过某些点作一个多边形,使这个多边形能把所有点都“包”起来.当这个多边形是凸多边形的时候,我们就叫它“凸包”.如下图: 然后,什么是凸包 ...
- LA 4728 旋转卡壳算法求凸包的最大直径
#include<iostream> #include<cstdio> #include<cmath> #include<vector> #includ ...
- POJ1113:Wall (凸包:求最小的多边形,到所有点的距离大于大于L)
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
随机推荐
- web api添加拦截器
实现思路 1.标识控制器有拦截特性: 2.控制器拦截处理: 代码实现 1.标识控制器有拦截特性,代码: [MyFilter] public string PostFindUser([FromBody] ...
- Core Java 总结(异常类问题)
所有代码均在本地编译运行测试,环境为 Windows7 32位机器 + eclipse Mars.2 Release (4.5.2) 2016-10-17 整理 下面的代码输出结果是多少?为什么?并由 ...
- 原生JS实现"旋转木马"效果的图片轮播插件
一.写在最前面 最近都忙一些杂七杂八的事情,复习软考.研读经典...好像都好久没写过博客了... 我自己写过三个图片轮播,一个是简单的原生JS实现的,没有什么动画效果的,一个是结合JQuery实现的, ...
- Wizard Framework:一个自己开发的基于Windows Forms的向导开发框架
最近因项目需要,我自己设计开发了一个基于Windows Forms的向导开发框架,目前我已经将其开源,并发布了一个NuGet安装包.比较囧的一件事是,当我发布了NuGet安装包以后,发现原来已经有一个 ...
- 利用Python进行数据分析(2) 尝试处理一份JSON数据并生成条形图
一.JSON 数据准备 首先准备一份 JSON 数据,这份数据共有 3560 条内容,每条内容结构如下: 本示例主要是以 tz(timezone 时区) 这一字段的值,分析这份数据里时区的分布情况. ...
- [占位-未完成]scikit-learn一般实例之十:核岭回归和SVR的比较
[占位-未完成]scikit-learn一般实例之十:核岭回归和SVR的比较
- shell脚本规划化模板
shell脚本规划化模板 Linux运维过程中,shell脚本是不可缺少的工具,但是每个运维人员编程的习惯都不一样,很多时候就是实现某个功能,写出来的脚本都是烂七八糟的.脚本必须规范化,应该从以后几个 ...
- malloc 与 free函数详解<转载>
malloc和free函数详解 本文介绍malloc和free函数的内容. 在C中,对内存的管理是相当重要.下面开始介绍这两个函数: 一.malloc()和free()的基本概念以及基本用法: 1 ...
- stream_set_timeout (fread 造成了php程序timeout)
最近在执行fread时候,php出现了 "Fatal error: Maximum execution time of 30 seconds " fread() :从文件指针 ha ...
- GJM : Unity3D HIAR -【 快速入门 】 八、开发云识别应用
开发云识别应用 为了解决识别图片数量限制,以及上线应用不能动态修改识别图片和 AR 内容的问题,我们在 HiAR SDK for Unity 新版本(v1.1.x 及后续版本)中集成了云识别功能.本文 ...