POJ 1113 Wall(计算几何の凸包)
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
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.
#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(计算几何の凸包)的更多相关文章
- POJ 1113 Wall【凸包周长】
题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- 2018.07.04 POJ 1113 Wall(凸包)
Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...
- POJ 1113 Wall(凸包)
[题目链接] http://poj.org/problem?id=1113 [题目大意] 给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度 [题解] 画图易得答案为凸包的 ...
- POJ 1113 Wall 求凸包
http://poj.org/problem?id=1113 不多说...凸包网上解法很多,这个是用graham的极角排序,也就是算导上的那个解法 其实其他方法随便乱搞都行...我只是测一下模板... ...
- POJ 1113 Wall 求凸包的两种方法
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31199 Accepted: 10521 Descriptio ...
- POJ 1113 Wall (凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- 题解报告:poj 1113 Wall(凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- poj 1113 Wall 凸包的应用
题目链接:poj 1113 单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...
- 【POJ】1113 Wall(凸包)
http://poj.org/problem?id=1113 答案是凸包周长+半径为l的圆的周长... 证明?这是个坑.. #include <cstdio> #include <c ...
随机推荐
- JavaScript数组处理方法
JavaScript中创建数组有两种方式 (一)使用 Array 构造函数: var arr1 = new Array(); //创建一个空数组 var arr2 = new Array(20); / ...
- 一、Vue项目构建
Attention:以下内容为Mac机上运行,windows可能有所偏差- Step1 打开终端,键入npm install -g vue-cli,使用vue-cli脚手架搭建vue项目能省很多事儿- ...
- Elasticsearch 数据操作
一.新增数据 1.1 随机生成id 语法: POST /索引库名/类型名 { "key1": "value1", "key2": " ...
- Hadoop核心架构(1)
在大数据的发展过程中,出现了一批专门应用与大数据的处理分析工具,如Hadoop,Hbase,Hive,Spark等,我们先从最基础的Hadoop开始进行介绍 Hadoop是apache基金会下所开发的 ...
- OpenWrt超时检测
参考http://www.right.com.cn/forum/thread-261702-1-1.html vim /home/ihid/chaos_calmer/feeds/luci/module ...
- 查看Pyton的版本号和32/64位平台
怎么查看Python的版本号?使用的Python是32位还是64位的?用以下两条Python 指令就可以知道. 方法1:通过Python代码查看 import platform import sys ...
- pyhton 下 使用getch(), 输入字符无需回车
原代码来自 https://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin ...
- 使用ABAP CDS视图创建服务
介绍本文介绍使用ABAP Core Data Services创建OData服务的最快方法. 给出了有关@ OData.publish注释利用率,对数据源CDS实体的引用和从DDIC结构导入的详细信息 ...
- Prism for WPF 搭建一个简单的模块化开发框架(四)异步调用WCF服务、WCF消息头添加安全验证Token
原文:Prism for WPF 搭建一个简单的模块化开发框架(四)异步调用WCF服务.WCF消息头添加安全验证Token 为什么选择wcf? 因为好像wcf和wpf就是哥俩,,, 为什么选择异步 ...
- mySql——case when else ....demo
DROP PROCEDURE IF EXISTS Pro_query_change_charge_by_layer_report; CREATE PROCEDURE Pro_query_change_ ...