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. sd卡的访问

    一般再访问sd卡前都要获取sd卡的路径,以防止不同的厂商有不同的路径配置.Android提供了Environment类来获取系统当前sd卡路径. Log.d(TAG, Environment.getE ...

  2. 算法学习 并查集(Union-Find) (转)

    并查集是我暑假从高手那里学到的一招,觉得真是太精妙的设计了.以前我无法解决的一类问题竟然可以用如此简单高效的方法搞定.不分享出来真是对不起party了.(party:我靠,关我嘛事啊?我跟你很熟么?) ...

  3. 51nod 1257 背包问题 V3(分数规划)

    显然是分数规划...主要是不会求分数的形式,看了题解发现自己好傻逼QAQ 还是二分L值算出d[]降序选K个,顺便记录选择时候的p之和与w之和就可以输出分数形式了... #include<iost ...

  4. eclipse ide for java ee developers 开发环境搭建(J2EE) 【转载】

    使用eclipse真的有年头了,相信java程序员没有不知道它的,最近在给团队中新来的应届生做指导,专门讲解了一下Eclipse开发环境的搭建过程, 一是帮助他们尽快的熟悉IDE的使用,二也是保证团队 ...

  5. python练习:抓取统计log内ip数量

    #!/usr/bin/python #-*- coding: utf- -*- import os import re rawfile = '/var/log/auth.log' def rawpar ...

  6. 一个完整的upstart脚本分析

    基本概念可以了解 http://www.mike.org.cn/articles/understand-upstart/ http://blog.fens.me/linux-upstart/ http ...

  7. bzoj 4206 最大团 几何+lis

    最大团 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 142  Solved: 65[Submit][Status][Discuss] Descrip ...

  8. 企业CEO最核心的应该是销售意识

    一个企业的本质是赚利润,利润怎么来?靠卖东西,所以企业里面最重要的应该是销售人员.在一些500强的外企里有一个规定,没有做过销售的人是很难升到总经理的,在以色列的军队中,没有当过班长,是不可以被提拔为 ...

  9. es6异步操作

    异步编程对 JavaScript 语言太重要.JavaScript 只有一根线程,如果没有异步编程,根本没法用,非卡死不可. ES6 诞生以前,异步编程的方法,大概有下面四种. 回调函数 事件监听 发 ...

  10. 【CSS】凹槽的写法

    效果图: 实例代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...