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. 关于 Swift 中的 Array.contains 方法

    Swift 2.0 中对语言进行了又一次的改进,这次将整个语言变得更加面向对象化,比如在 Swift 1.x 中如果要判断某个元素是否在数组中,就需要用到 contains 函数: if contai ...

  2. WPF控件的一些特殊应用

    1 checkbox.IsChecked 返回的是bool?类型,需要用bool强转,或者直接和bool类型比较,将发生隐形转换 2 RadioButton有分组属性GroupName

  3. WPF 动态模拟CPU 使用率曲线图

    原文:WPF 动态模拟CPU 使用率曲线图      在工作中经常会遇到需要将一组数据绘制成曲线图的情况,最简单的方法是将数据导入Excel,然后使用绘图功能手动生成曲线图.但是如果基础数据频繁更改, ...

  4. JSTL自定义标签 实现forEach循环支持集合.数组

    java代码实现 tld配置 JSP页面代码

  5. MVC WebApi的两种访问方法

    //UserInfoController using ClassLibrary; using System;using System.Collections.Generic;using System. ...

  6. 数据绑定(七)使用ObjectDataProvider对象作为Binding的Source

    原文:数据绑定(七)使用ObjectDataProvider对象作为Binding的Source ObjectDataProvider就是把对象作为数据源提供给Binding,类似的还有XmlData ...

  7. liunx 详细常用操作

    图片来自: http://www.cnblogs.com/zhangsf/archive/2013/06/13/3134409.html 公司新员工学习有用到,Vim官网的手册又太大而全,而网上各方资 ...

  8. fileapi.h里的API函数(包括LockFileEx和FindFirstChangeNotification函数)

    /** * This file is part of the mingw-w64 runtime package. * No warranty is given; refer to the file ...

  9. UWP ListView

    ListViewItem项填充整个宽度最大化<ListView.ItemContainerStyle> <Style TargetType="ListViewItem&qu ...

  10. Android零基础入门第3节:带你一起来聊一聊Android开发环境

    原文:Android零基础入门第3节:带你一起来聊一聊Android开发环境 工欲善其事,必先利其器.Android开发人员在自己的计算机上编写和测试应用程序,然后将其部署到实际的设备上,那首先必不可 ...