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. hdu6184 Counting Stars 【三元环计数】

    题目链接 hdu6184 题解 题意是让我们找出所有的这样的图形: 我们只需要求出每条边分别在多少个三元环中,记为\(x\),再然后以该点为中心的图形数就是\({x \choose 2}\) 所以我们 ...

  2. JavaScript数据类型转换方法汇总

    转换为布尔型 用两次非运算(!): 1 !!5 ==> true 用布尔型的构造函数: 1 new Boolean(5) == > true 值转换为布尔类型为false:0,+0,-0, ...

  3. angularJS批量删除 品优购删除品牌(通用复选框批量选中删除解决思路)

    思路: 一步:在点击复选框时维护变量数组 在js中定义一个数组变量, 给复选框添加点击动作, 在动作中判断当前复选框是否为选中状态(即点击后复选框的是否选中状态), 若为选中状态,则向数组中添加选中的 ...

  4. SpringMVC源码解析-DispatcherServlet启动流程和初始化

    在使用springmvc框架,会在web.xml文件配置一个DispatcherServlet,这正是web容器开始初始化,同时会在建立自己的上下文来持有SpringMVC的bean对象. 先从Dis ...

  5. 由一篇博文做出的代码,不用Math.round()如何实现其功能

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. uboot 的命令体系

    1.代码位置 (1)uboot命令体系的实现代码在uboot/common/cmd_xxx.c中.有若干个.c文件和命令体系有关.(还有command.c  main.c也是和命令有关的) 2.传参方 ...

  7. 旋转 3d

    建议chorme浏览器浏览,有样式兼容性问题. 图片可以根据自己本地路径设置路径,js库引用jquery. 写的不好,多多建议,谢谢大家. <html onselectstart="r ...

  8. [LeetCode] 6. ZigZag Conversion ☆☆☆

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  9. java 反射和new的区别

    关于java 反射和new的区别,在这里我不做多讲,因为网上有大把资料,描述得很详细. 今天我只讲一点,为什么要用反射?直接用new不行么?干嘛弄得那么麻烦! 1.基本上效果差不多,但是new对象,无 ...

  10. MongoDB入门(8)- c#通过操作MongoDB GridFS实现文件的数据库存储

    GridFS介绍 GridFS是MongoDB中的一个内置功能,可以用于存放大量小文件. GridFS GridFS长啥样 /* 1 */ { "_id" : ObjectId(& ...