Wall(HDU1348,凸包周长)
来源:互联网 发布:巨人通力知乎 编辑:程序博客网 时间:2024/05/16 13:05
http://acm.hdu.edu.cn/showproblem.php?pid=1348
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=29328#problem/A
A - Wall
HDU 1348
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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Sample Input
1
9 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200
Sample Output
1628
解析:
思路:
求出凸包周长+一个半r为圆的周长
圆的周长如何得到呢?例如下图
拐角处的周长即是圆的周长
276 KB 15 ms C++ 1161 B
*/
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include <iostream>using namespace std;const int maxn=2000+10;const double eps=1e-9;const double pi=acos(-1.0);int n,m;struct point{double x;double y;}p[maxn],ch[maxn];double Cross(point A,point B){return A.x*B.y-A.y*B.x;}point sub(point a,point b){point c;c.x=a.x-b.x;c.y=a.y-b.y;return c;}bool cmp(point A,point B){return A.x<B.x||(A.x==B.x&&A.y<B.y);}double dis(point A,point B){return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));}void ConvexHull(){sort(p,p+n,cmp);m=0;for(int i=0;i<n;i++){while(m>1&&Cross(sub(ch[m-1],ch[m-2]),sub(p[i],ch[m-2]))<=0)m--;ch[m++]=p[i];}int k=m;for(int i=n-2;i>=0;i--){while(m>k&&Cross(sub(ch[m-1],ch[m-2]),sub(p[i],ch[m-2]))<=0)m--;ch[m++]=p[i];}if(n>1)m--;}int main(){int T,i;double r;scanf("%d",&T);while(T--){scanf("%d%lf",&n,&r);for(i=0;i<n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);double ans=0;ConvexHull();for(i=0;i<m;i++){ans+=dis(ch[i],ch[(i+1)%m]);}ans+=2*pi*r;printf("%.0lf\n",ans);if(T>0)printf("\n");}return 0;}
- Wall(HDU1348,凸包周长)
- hdu1348 Wall(凸包)
- hdu1348 Wall 凸包
- HDU1348 Wall 凸包
- hdu1348 Wall(凸包模板题)
- hdu1348 Wall (求凸包周长)
- HDU1348 Wall 【简单凸包】
- poj 1113 Wall(凸包周长)
- [ACM] hdu Wall (凸包周长)
- POJ1113 Wall(凸包周长)
- POJ 1113 Wall(凸包周长)
- POJ 1113 Wall (凸包+求周长)
- POJ 1113 Wall【凸包周长】
- POJ 1113 Wall (凸包周长)
- POJ 1113 Wall(凸包周长)
- POJ 1113 Wall(凸包 多边形周长)
- HDU 1348 Wall 凸包的周长
- [HDU 1348] Wall 凸包周长
- 数据库系统管理与维护
- initwithcoder和 initwithframe 区别?
- php日志处理
- 浅谈spring——spring MVC(十一)
- gcc 安装详解
- Wall(HDU1348,凸包周长)
- PendingIntent详解
- 论C++构造函数中的不合理设计
- 熟悉jdk与jre区别有助于开发
- Linux学习之道:linux下的bash与sh 详解以及例子
- mysql 语句case when
- 无限大的两个整数相加
- POJ 3169 差分约束
- Toy Storage(poj2398,向量叉乘+二分查找)