Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 31419   Accepted: 10619

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

结果四舍五入就可以了

Source

题意:给出一个多边形,坐标按照顺时针的方向给出,然后要求给此多边形扎个围墙,并且围墙到多边形的距离等于L
做法:graham

附:

针对上面的公式(1)copy一个证明:http://blog.sina.com.cn/s/blog_687916bf0100jq9g.html

证明如下:假如顺时针给出四个点A、B、C、D。组成了凸四边形ABCD。我们不妨过A点作AE垂直于AB,同时过A点再作AF垂直于AD,过B点 作BG、BH分别垂直于AB、BC。连结EG,垂线段的长度为L,过A点以AE为半径作一段弧连到AF,同理,使GH成为一段弧。此时 EG=AB(边),AB段城墙的最小值为EF+弧EF+弧GH=AB+弧EF+弧GH。对所有点进行同样的操作后,可知城墙的最小值=四边形的周长+相应 顶点的弧长(半径都为L)之和。

下面证明这些顶点弧长组成一个圆。依然以前面的四边形为例。A、B、C、D四顶点各成周角,总和为360*4=1440度,四边形内角和为360度,每个顶点作两条垂线,总角度为4*2*90=720度,所以总圆周角为1440-360-720=360度,刚好组成圆。

所以四边形ABCD的围墙最短= 四边形的周长+圆周长。

推广到任意多边形,用同样的方法,城墙最短=凸包的周长 + 以L为半径的圆的周长。

首先,我们得出城墙最短=凸包的周长 + 相应顶点的弧长(半径都为L)之和。

再证明 相应顶点的弧长(半径都为L)之和=以L为半径的圆的周长。

事实上,设凸包顶点为n,n个顶点组成n个周角,角度为360*n=2*180*n,凸包的内角和为180*(n-2),作了2*n条垂线,和为2*n*90=180*n,所以总圆周角为2*180*n-180*(n-2)-180*n=360,组成圆。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
#define pi 3.141592653
#define maxn 1010
#define eps 1e-8
using namespace std;
int Stack[maxn];
int top ;
struct Point
{
int x;
int y;
Point() {}
} List[maxn];
int cross(Point p0,Point p1,Point p2) //计算叉积 p0p1 X p0p2
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
double dist(Point p1,Point p2) //计算 p1p2的 距离
{
return sqrt((double)(p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
bool cmp(Point p1,Point p2)
{
int tmp = cross(List[],p1,p2);
if(tmp >) return true;
else if(tmp== && dist(List[],p1) < dist(List[],p2)) return true;
else return false;
}
void graham(int n)
{
// scanf("%d %d",&List[0].x,&List[0].y);
Point p0;
int k=;
p0 = List[];
for(int i=; i<n; i++)
{
// scanf("%d %d",&List[i].x,&List[i].y);
if( (p0.y>List[i].y) || ((p0.y==List[i].y)&&(p0.x>List[i].x)) )
{
p0 = List[i];
k = i;
}
}
List[k] = List[];
List[] = p0;
sort(List+,List+n,cmp);
if(n == )
{
top = ;
Stack[] = ;
}
if(n == )
{
top = ;
Stack[] = ;
Stack[] = ;
}
if(n > )
{
Stack[] = ;
Stack[] = ;
top = ;
for(int i=; i<n; i++)
{
while(top > && cross(List[Stack[top-]],List[Stack[top]],List[i])<=) top--;
top++;
Stack[top] = i;
}
}
}
int main()
{
// freopen("in.txt","r",stdin);
int n,l;
while(~scanf("%d %d",&n,&l))
{
memset(List,,sizeof(List));
memset(Stack,,sizeof(Stack));
// init(n);
for(int i=;i<n;i++)
{
scanf("%d %d",&List[i].x,&List[i].y);;
}
graham(n);
double sum = ;
for(int i=; i<top; i++)
{
sum += dist(List[Stack[i]],List[Stack[i+]]);
}
sum += dist(List[Stack[]],List[Stack[top]]);
sum = sum + * pi * l;
printf("%d\n",(int)(sum+0.5));
}
}

poj-1113的更多相关文章

  1. 计算几何--求凸包模板--Graham算法--poj 1113

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28157   Accepted: 9401 Description ...

  2. poj 1113 凸包周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33888   Accepted: 11544 Descriptio ...

  3. POJ 1113 Wall 凸包 裸

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

  4. poj 1113 Wall 凸包的应用

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

  5. 【POJ 1113】Wall

    http://poj.org/problem?id=1113 夏令营讲课时的求凸包例题,据说是PKUSC2015的一道题 我WA两次错在四舍五入上了(=゚ω゚)ノ #include<cmath& ...

  6. poj 1113 Wall

    题目链接:http://poj.org/problem?id=1113 题目大意:给出点集和一个长度L,要求用最短长度的围墙把所有点集围住,并且围墙每一处距离所有点的距离最少为L,求围墙的长度. 解法 ...

  7. ●POJ 1113 Wall

    题链: http://poj.org/problem?id=1113 题解: 计算几何,凸包 题意:修一圈围墙把给出的点包围起来,且被包围的点距离围墙的距离不能小于L,求围墙最短为多少. 答案其实就是 ...

  8. POJ 1113 Wall(凸包)

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

  9. POJ 1113 Wall【凸包周长】

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

  10. POJ 1113 Wall 求凸包

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

随机推荐

  1. js判断设备类型

    1. 判断微信 function is_weixin() { var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/Micr ...

  2. purfer序列题表

    purfer序列是对于带编号(互不相同)的无根树进行编码得到的,对于同样的n个顶点,其有n-2项,有n^(n-2)种,而且每种都合法(如果只要求他是一棵树的话)(可以通过证明翻译过程维持了各部分的树的 ...

  3. ACM1598并查集方法

    find the most comfortable road Problem Description XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Struc ...

  4. HDU1260DP

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  5. Moq 和 RhinoMocks

    我们在做单元测试的时候,利用mock可轻松构建出测试需要的类或接口,而不需要编写繁琐的测试代码. .net 下我知道Moq与Rhino Mocks这两个框架. Moq 网上介绍的比较多. Rhino ...

  6. 【Codeforces441E】Valera and Number [DP]

    Valera and Number Time Limit: 20 Sec  Memory Limit: 512 MB Description Input Output Sample Input 5 3 ...

  7. Vue 使用中的小技巧(山东数漫江湖)

    在vue的使用过程中会遇到各种场景,当普通使用时觉得没什么,但是或许优化一下可以更高效更优美的进行开发.下面有一些我在日常开发的时候用到的小技巧,在下将不定期更新~ 1. 多图表resize事件去中心 ...

  8. bzoj 1968 数学

    在1-n所有数中,i一共可以成为n/i个数的约数,也即所有的约数中有n/i个i,所以扫一遍累加答案就好了. /********************************************* ...

  9. Android Studio 中引入Library

    启动AndroidStudio后,打开你需要接收Library的项目.比如有两个项目,项目A,和Library项目B,那么打开项目A.图中所示为项目的结构图,点击右上角的File菜单. 2 在下拉菜单 ...

  10. 空间数据库系列二:空间索引S2与Z3分析对比

    S2与Z3对比分析 1. S2 2. Geohash 3. Geomesa Z3 4. S2对比geohash 4.1. geohash存在的问题 4.2. S2优势 4.3. 实际对比例子 5. 测 ...