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. C#原子性运算 interlocked.compareExchanged

    缘起: 假设有一个类myClass, myclass里有一个count属性. 在多线程的环境下 每个线程中 直接使用count++,  如果两个线程并行执行时, 两个线程中的一个的结果会被覆掉, 非线 ...

  2. WPF分辨率适应

    double x = SystemParameters.WorkArea.Width;//得到屏幕工作区域宽度 double y = SystemParameters.WorkArea.Height; ...

  3. BGP路由的手动汇总

    网络拓扑 XRV1 ========================================================== !hostname XRV1!interface Loopba ...

  4. 零元学Expression Blend 4 - Chapter 45 ListBox里的物件不能换行吗?

    原文:零元学Expression Blend 4 - Chapter 45 ListBox里的物件不能换行吗? ListBox里的排列不是垂直就是水平,觉得这样的排列很枯燥乏味吗? 想要它变聪明吗? ...

  5. eclipse 插件编写(三)

    参考:http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_ ...

  6. SharePoint Add-in Model (App Model) 介绍 – 概念、托管方式、开发语言

    SharePoint Add-in Model 是自 2013 版本以来引入的新的扩展性开发模型, SharePoint 开发者可以利用这种新模型来实现往常利用场解决方案 (Farm Solution ...

  7. 谷歌推出全新Android开发语言Sky:让App更流畅

    土豆网同步更新:http://www.tudou.com/plcover/VHNh6ZopQ4E/   使用HTML 创建Mac OS App 视频教程. 官方QQ群: (1)App实践出真知 434 ...

  8. Delphi结束进程模块

    function KillTask(ExeFileName: string): integer; const PROCESS_TERMINATE = $0001; var ContinueLoop: ...

  9. 枚举当前系统用户(使用NetUserEnum API枚举)

    using System.Runtime.InteropServices;   [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unico ...

  10. 插件化二(Android)

    插件化二(Android) 上一篇文章<插件化一(android)>里大概构思了下插件加载与校验的流程和一些大体设计,这次就具体展开,在<动态加载与插件化>里提到以apk形式开 ...