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. node.js学习笔记之json数据转string

    Node.js中的JSON问题   var str = '{"dir":"kunhony","param":"archive&qu ...

  2. C# 异步委托的使用

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  3. 绕过010Editor网络验证(用python做一个仿真http server真容易,就几行代码)

    010Editor是一款非常强大的十六进制编辑器,尤其是它的模板功能在分析文件格式时相当好用!网上现在也有不少010Editor的破解版,如果没钱或者舍不得花钱买授权的话,去官方下载安装包再使用注册机 ...

  4. GIS基础软件及操作(七)

    原文 GIS基础软件及操作(七) 练习七.地形分析 地形分析:TIN及DEM的生成及应用 加深对TIN建立过程的原理.方法的认识: 熟练掌握ArcGIS中建立DEM.TIN的技术方法: 结合实际,掌握 ...

  5. Android零基础入门第18节:EditText的属性和使用方法

    原文:Android零基础入门第18节:EditText的属性和使用方法 EditText与TextView非常相似,它甚至与TextView 共用了绝大部分XML属性和方法.EditText与Tex ...

  6. 十个 Web 开发者熟悉的经典开源项目和工具

    摘要: 一个都不知道的算我输! 这篇文章主要列出了曾经乃至现在都十分受 Web 开发者欢迎的开源工具,相信使用开源工具的 Web 开发者会对它们感兴趣的,它们中有的甚至诞生十多年了,但仍然在发光发热. ...

  7. C#图片灰度处理(位深度24→位深度8),用灰度数组byte[]新建一个8位灰度图像Bitmap 。

    原文:C#图片灰度处理(位深度24→位深度8) #region 灰度处理 /// <summary> /// 将源图像灰度化,并转化为8位灰度图像. /// </summary> ...

  8. CoolFormat(Qt Creator也可管理VC的Project)

    http://download.csdn.net/download/akof1314/8457593 https://github.com/akof1314/CoolFormat http://dow ...

  9. SQL语法详解

    ALTER DATABASE修改数据库全局特性 ALTER DATABASE实际上是修改数据库目录中的dp.opt文件 ALTER TABLE修改表的结构 ALTER TABLE对表进行增删列,创建取 ...

  10. Linux SD卡建立两个分区

    本文主要介绍Linux 环境下 SD 卡建立两个分区的操作流程: 操作环境:Linux Ubuntu 2016.4 操作目的:将 SD 卡分为两个分区:第一分区格式为 FAT32,大小 500M.第二 ...