Wall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 28462   Accepted: 9498

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


 
  计算几何,求凸包周长
  poj上的一道求凸包的经典题,和hdu上 hdu 1348:Wall(计算几何,求凸包周长) 一样,只不过输入输出格式有些不同。代码拿过来改了改就A了。
  思路见以上博客。
  本题需注意的是,要求四舍五入,最后在强制转换之前+0.5即可。另外,用C++的方式输入输出(cin,cout)可能会超时。
  代码
 #include <iostream>
#include <cmath>
#include <iomanip>
#include <stdio.h>
using namespace std;
struct Point{
double x,y;
};
double dis(Point p1,Point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double xmulti(Point p1,Point p2,Point p0) //求p1p0和p2p0的叉积,如果大于0,则p1在p2的顺时针方向
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double graham(Point p[],int n) //点集和点的个数
{
int pl[],i;
//找到纵坐标(y)最小的那个点,作第一个点
int t = ;
for(i=;i<=n;i++)
if(p[i].y < p[t].y)
t = i;
pl[] = t;
//顺时针找到凸包点的顺序,记录在 int pl[]
int num = ; //凸包点的数量
do{ //已确定凸包上num个点
num++; //该确定第 num+1 个点了
t = pl[num-]+;
if(t>n) t = ;
for(i=;i<=n;i++){ //核心代码。根据叉积确定凸包下一个点。
double x = xmulti(p[i],p[t],p[pl[num-]]);
if(x<) t = i;
}
pl[num] = t;
} while(pl[num]!=pl[]);
//计算凸包周长
double sum = ;
for(i=;i<num;i++)
sum += dis(p[pl[i]],p[pl[i+]]);
return sum;
}
const double PI = 3.1415927;
int main()
{
int N,i;
double L;
Point p[];
cout<<setiosflags(ios::fixed)<<setprecision();
while(scanf("%d%lf",&N,&L)!=EOF){
for(i=;i<=N;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
printf("%d\n",int(graham(p,N)+*PI*L+0.5));
}
return ;
}

Freecode : www.cnblogs.com/yym2013

poj 1113:Wall(计算几何,求凸包周长)的更多相关文章

  1. POJ 1113 Wall(计算几何の凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  2. POJ-1113 Wall 计算几何 求凸包

    题目链接:https://cn.vjudge.net/problem/POJ-1113 题意 给一些点,求一个能够包围所有点且每个点到边界的距离不下于L的周长最小图形的周长 思路 求得凸包的周长,再加 ...

  3. The Fortified Forest - POJ 1873(状态枚举+求凸包周长)

    题目大意:有个国王他有一片森林,现在他想从这个森林里面砍伐一些树木做成篱笆把剩下的树木围起来,已知每个树都有不同的价值还有高度,求出来砍掉那些树可以做成篱笆把剩余的树都围起来,要使砍伐的树木的价值最小 ...

  4. POJ 1113 Wall 凸包 裸

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

  5. POJ 1113 Wall(Graham求凸包周长)

    题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...

  6. hdu 1348:Wall(计算几何,求凸包周长)

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

  7. POJ 1113 Wall (凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  8. hdu 1392:Surround the Trees(计算几何,求凸包周长)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. HDU 1392 凸包模板题,求凸包周长

    1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...

随机推荐

  1. memcached 系列2:memcached实例(转载)

    在上一篇文章,我们讲了,为什么要使用memched做为缓存服务器(没看的同学请点 这里).下面让我们以memcached-1.2.1-win32版本的服务组件(安装后是以一个windows服务做dae ...

  2. jQuery Uploadify在ASP.NET MVC中的使用

    感谢http://www.cnblogs.com/libingql/archive/2012/09/11/2681007.html 除此之外,给大家推荐一个: http://gallery.kissy ...

  3. fatl exception occurred异常/错误的一种可能情况

    如果,有可能是 java.lang.ClassLoader类内部出错,请自行检查

  4. iOS-UIView category

    UIView+Extension.h #import <UIKit/UIKit.h> @interface UIView (Extension) @property (nonatomic, ...

  5. IMEI是什么? 怎样查手机串号IMEI

    IMEI的基本含义 IMEI(International Mobile Equipment Identity,移动设备国际识别码,又称为国际移动设备标识)是手机的唯一识别号码.我们从这个缩写的全称中来 ...

  6. android TP驱动移植调试笔记(转)

    1. 添加I2C 设备 TP 一般采用的是I2C 作为数据和命令接口,所以TP 驱动也可以归类为I2C 驱动.TP驱动的主要逻辑不在这里,但是了解了Linux 的I2C 体系架构,就可以对整个驱动流程 ...

  7. motto4

    有时候,你不能太固执,因为这样子对你不利,应该懂得变通才行. 你要知道,语言是表达思想的工具.你不说,别人怎么知道你的思想呢?你又怎么了解他人的思想呢?

  8. (JS高手不用看了!我只是在碎碎念,因为我也不知道面什么)JavaScript的算术运算

    Math.pow(2,53)    //2的51次幂 Math.round(0.6)    //四舍五入 Math.cell(0.6)      //向上求整 Math.floor(0.6)    / ...

  9. Matlab数值计算最简单的一个例子——指数衰减

    放射性衰变是指数衰减的典型例子.另外还有化学反应某反应物的减少,RC电路电流的减小,大气压随海拔高度的减小等. 指数衰减的方程: \begin{equation} \frac{dN(t)}{dt}=- ...

  10. 用WP_Query自定义WordPress 主循环

    我们知道操作 WordPress 主循环(WordPress Loop)最容易的方法是使用 query_posts 函数. 但是使用 query_posts 直接修改 WordPress 默认的主循环 ...