http://poj.org/problem?id=1113

Wall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 34616   Accepted: 11821

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

9 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200

Sample Output

1628

Hint

结果四舍五入就可以了
 
丢一个kuangbin的凸包模板。。
 #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(凸包)的更多相关文章

  1. POJ 1113 Wall 凸包 裸

    LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...

  2. poj 1113 Wall 凸包的应用

    题目链接:poj 1113   单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...

  3. POJ 1113 Wall 凸包求周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26286   Accepted: 8760 Description ...

  4. POJ 1113 - Wall 凸包

    此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...

  5. poj 1113 wall(凸包裸题)(记住求线段距离的时候是点积,点积是cos)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43274   Accepted: 14716 Descriptio ...

  6. POJ 1113 Wall【凸包周长】

    题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  7. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  8. POJ 1113 Wall(凸包)

    [题目链接] http://poj.org/problem?id=1113 [题目大意] 给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度 [题解] 画图易得答案为凸包的 ...

  9. POJ 1113 Wall 求凸包

    http://poj.org/problem?id=1113 不多说...凸包网上解法很多,这个是用graham的极角排序,也就是算导上的那个解法 其实其他方法随便乱搞都行...我只是测一下模板... ...

  10. POJ 1113 Wall 求凸包的两种方法

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31199   Accepted: 10521 Descriptio ...

随机推荐

  1. Python第一个基本教程4章 词典: 当指数不工作时也

    Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "copyri ...

  2. Convert和RelativeSource

    自定义Converter 后台Converter类实现接口IValueConverter方法Convert是值->UI方法ConvertBack是UI->值初始化走Convert publ ...

  3. fail2ban防止暴力破解

    安装fail2ban: 将fail2ban 上传到服务器,解压: [root@xuegod1 tmp]# tar -zxvf fail2ban-0.8.14.tar.gz [root@xuegod1 ...

  4. 数组/LINQ/List/ObservableCollection

    private static void AddIndustryTypes(sectorCode[] result) { var industryTypes = (from t in result se ...

  5. 一个字体,大小,颜色可定义的自绘静态框控件-XColorStatic 类(比较好看,一共19篇自绘文章)

    翻译来源:https://www.codeproject.com/Articles/5242/XColorStatic-a-colorizing-static-control XColor Stati ...

  6. C# 优先级队列

    前6行是优先队列,后6行是C#原生的queue Min Heap Priority Queue Works with: C# version 3.0+/DotNet 3.5+ The above co ...

  7. 使用ServiceStack.Redis实现Redis数据读写

    原文:使用ServiceStack.Redis实现Redis数据读写 User.cs实体类 public class User { public string Name { get; set; } p ...

  8. delphi文件操作(比较全)

    Delphi中默认有input和output两个文件变量,使用可以不用定义,直接使用. 但: input:只读.output:只写.用时注意以免引起异常. 文件是由文件名标识的一组数据的集合,文件通常 ...

  9. WPF 鼠标在图片Image上悬停时切换更改设置图片源Source

    // 无效的写法,图片不会被切换 <Image Margin="0,0,0,0" Width="50" Height="50" Sou ...

  10. Central Subscriber Model Explained

    原文 http://www.sqlrepl.com/sql-server/central-subscriber-model-explained/ The majority of SQL Server ...