博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【POJ1113】Wall(凸包)
阅读量:4641 次
发布时间:2019-06-09

本文共 3707 字,大约阅读时间需要 12 分钟。

【题目】

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 100200 400300 400300 300400 300400 400500 400500 200350 200200 200

Sample Output

1628
代码如下:
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 using namespace std; 9 #define Maxn 101010 11 struct Point12 {13 double x,y;14 Point(double x=0,double y=0):x(x),y(y) {}15 };16 17 typedef Point Vector;18 Point p[Maxn];19 20 int n,l;21 const double pi=3.1415926535898;22 23 double myabs(double x) { return x<0?-x:x;}24 25 const double eps=1e-10;26 int dcmp(double x)//判断正负和零27 {28 if(myabs(x)
1&&Cross(ch[len]-ch[len-1],p[i]-ch[len-1])<=0) len--;46 ch[++len]=p[i];47 }int k=len;48 for(int i=n-1;i>=1;i--)49 {50 while(len>k&&Cross(ch[len]-ch[len-1],p[i]-ch[len-1])<=0) len--;51 ch[++len]=p[i];52 }53 if(n>1) len--;54 }55 56 double PolygonLength()57 {58 double L=0;59 for(int i=2;i<=len;i++)60 L+=Length(ch[i]-ch[i-1]);61 L+=Length(ch[1]-ch[len]);62 return L;63 }64 65 int main()66 {67 scanf("%d%d",&n,&l);68 for(int i=1;i<=n;i++)69 {70 scanf("%lf%lf",&p[i].x,&p[i].y);71 }72 sort(p+1,p+1+n,cmp);73 covexhull();74 printf("%.0f\n",PolygonLength()+pi*l*2);75 return 0;76 }
[POJ1113]
 

 

2016-04-28 19:32:02

 
 

转载于:https://www.cnblogs.com/Konjakmoyu/p/5443953.html

你可能感兴趣的文章
开发Nginx模块Helloworld
查看>>
【BZOJ】4542: [Hnoi2016]大数
查看>>
通过注入DLL后使用热补丁钩取API
查看>>
欧拉筛(线性筛)
查看>>
C 语言指针怎么理解
查看>>
Go基础1
查看>>
删除数据库所有表数据
查看>>
kali下搭建WiFi钓鱼热点
查看>>
【Java】 剑指offer(32) 从上往下打印二叉树
查看>>
二十三、连接mysql数据库,创建用户模型
查看>>
leetcode--844:(队列类)比较含退格的字符串
查看>>
判断字符串是否全为空格和去掉字符串中的空格
查看>>
OO第一阶段纪实
查看>>
实验二
查看>>
ASP.NET Web API 2系列(一):初识Web API及手动搭建基本框架
查看>>
抄袭的用Jsp+JavaBean+Mysql实现的登录和注册
查看>>
jquery显示隐藏操作
查看>>
还是畅通工程(hdu1233)并查集应用
查看>>
导入.sql文件入数据库
查看>>
I/O模型
查看>>