[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 ...
随机推荐
- Java设计模式之策略模式(Strategy)
前言: 最近一直在学习基于okHttp网络请求,学习的过程中就想起了之前项目中有这么一个需求不同的接口要采用不同的加密方式,比如登录之前要采用RSA加密,登录之后要采用AES加密,当时是采用靠传递一个 ...
- java中的文件读取和文件写出:如何从一个文件中获取内容以及如何向一个文件中写入内容
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...
- HTML5 学习总结(二)——HTML5新增属性与表单元素
一.HTML5新增属性 1.1.contextmenu contextmenu的作用是指定右键菜单. <!DOCTYPE html> <html> <head> & ...
- Oracle 11.2.0.4单实例打PSU,OJVM PSU补丁快速参考
写在前面: 1.Oracel打每个补丁的操作有时存在差异,所以不管多熟悉,都应该在打任何补丁之前阅读新补丁中附带的readme. 2.Oracle每季度都会更新一个最新的PSU,本文最新指的是当前最新 ...
- 学习SpringMVC——拦截器
拦截器,顾名思义就是用来拦截的. 那什么是拦截,又为什么要拦截.对于Spring MVC来说,拦截器主要的工作对象就是用户的请求,拦截下来之后,我们可以在拦截的各个阶段悉心呵护[为所欲为].常见的比如 ...
- docker对数据卷容器进行备份
转载请注明出处 官网的数据以及各大博客都没有对这个的具体说明,本人也是理解了好久. 我们使用docker的过程中,使用共享的数据卷是经常的,那么.我们要怎么进行备份呢? 首先,我们得了解下面4个命 ...
- 你可曾见过如此简单粗暴的JavaScript解说 -- if 判断的正确打开方式?
在JavaScript中,对于 if else 的逻辑判断你肯定非常熟悉,本文罗列了几种你不一定知道的简写方式,仅供参考. 例子: 已知小明考了68分,小于60分为不及格,大于60分为及格,问:小明是 ...
- Qt 拷贝文件目录
bool copyDir(const QString &source, const QString &destination, bool override) { QDir direct ...
- ASP.NET MVC——CodeFirst开发模式
Entity Framework框架提供了几种开发模式,比如Database First,Model First,Code First.Database First是最老也是应用得最广泛的一种设计方式 ...
- JDBC 详解(转载)
原文链接:http://blog.csdn.net/cai_xingyun/article/details/41482835 什么是JDBC? Java语言访问数据库的一种规范,是一套API JDBC ...