POJ 1113:Wall(凸包)
http://poj.org/problem?id=1113
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 34616 | Accepted: 11821 |
Description

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.
Output
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
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define N 1005
const double PI = acos(-1.0); struct point
{
int x,y;
}p[N]; int stak[N],top, n, L; int cross(point p0, point p1, point p2)
{
return (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x);
}//计算叉积 p0p1 x p0p2 double dis(point p1, point p2)
{
return sqrt( (double)(p2.x - p1.x) * (p2.x - p1.x) + (double)(p2.y - p1.y) * (p2.y - p1.y) );
}//计算距离 p1p2的距离 bool cmp(point p1, point p2)
{
int tmp = cross(p[], p1, p2);
if(tmp > ) return true;
else if( tmp == && dis(p[], p1) < dis(p[], p2) ) return true;
return false;
}//极角排序函数,角度相同则距离小的在前面 void init()
{
point pp;
scanf("%d%d", &p[].x, &p[].y);
pp.x = p[].x, pp.y = p[].y;
int tmp = ;
for(int i = ; i < n; i++) {
scanf("%d%d", &p[i].x, &p[i].y);
if( (pp.y > p[i].y) || (pp.y == p[i].y) && (pp.x > p[i].x) ) {
tmp = i;
pp = p[i];
}
}
p[tmp] = p[];
p[] = pp;
sort(p+, p+n, cmp);
}//输入函数并进行预处理,将所有的点输入, 在最左下方的点放到p[0], 并进行极角排序 void Graham()
{
if(n <= ) {
top = ;
stak[] = ;
}
else if(n == ) {
top = ;
stak[] = ;
stak[] = ;
}
else{
stak[] = ;
stak[] = ;
top = ;
for(int i = ; i < n; i++) {
while( top > && cross(p[stak[top-]], p[stak[top]], p[i]) <= )
top--;
top++;
stak[top] = i;
}
}
}//凸包Graham模板 int main()
{
while(~scanf("%d%d",&n,&L)) {
init();
Graham(); //本题求的是凸包的周长 + 一个圆的周长
double res = ;
for(int i = ; i < top; i++) {
res += dis(p[stak[i]], p[stak[i+]]);
}
res += dis(p[stak[]], p[stak[top]]);
res += * L * PI; printf("%.0f\n", res);
}
return ;
}
POJ 1113:Wall(凸包)的更多相关文章
- POJ 1113 Wall 凸包 裸
LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...
- poj 1113 Wall 凸包的应用
题目链接:poj 1113 单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
- POJ 1113 - Wall 凸包
此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...
- poj 1113 wall(凸包裸题)(记住求线段距离的时候是点积,点积是cos)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43274 Accepted: 14716 Descriptio ...
- POJ 1113 Wall【凸包周长】
题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- 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 ...
随机推荐
- Python第一个基本教程4章 词典: 当指数不工作时也
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "copyri ...
- Convert和RelativeSource
自定义Converter 后台Converter类实现接口IValueConverter方法Convert是值->UI方法ConvertBack是UI->值初始化走Convert publ ...
- fail2ban防止暴力破解
安装fail2ban: 将fail2ban 上传到服务器,解压: [root@xuegod1 tmp]# tar -zxvf fail2ban-0.8.14.tar.gz [root@xuegod1 ...
- 数组/LINQ/List/ObservableCollection
private static void AddIndustryTypes(sectorCode[] result) { var industryTypes = (from t in result se ...
- 一个字体,大小,颜色可定义的自绘静态框控件-XColorStatic 类(比较好看,一共19篇自绘文章)
翻译来源:https://www.codeproject.com/Articles/5242/XColorStatic-a-colorizing-static-control XColor Stati ...
- C# 优先级队列
前6行是优先队列,后6行是C#原生的queue Min Heap Priority Queue Works with: C# version 3.0+/DotNet 3.5+ The above co ...
- 使用ServiceStack.Redis实现Redis数据读写
原文:使用ServiceStack.Redis实现Redis数据读写 User.cs实体类 public class User { public string Name { get; set; } p ...
- delphi文件操作(比较全)
Delphi中默认有input和output两个文件变量,使用可以不用定义,直接使用. 但: input:只读.output:只写.用时注意以免引起异常. 文件是由文件名标识的一组数据的集合,文件通常 ...
- WPF 鼠标在图片Image上悬停时切换更改设置图片源Source
// 无效的写法,图片不会被切换 <Image Margin="0,0,0,0" Width="50" Height="50" Sou ...
- Central Subscriber Model Explained
原文 http://www.sqlrepl.com/sql-server/central-subscriber-model-explained/ The majority of SQL Server ...