1113 Wall
来源:互联网 发布:淘宝永久封号怎么解除 编辑:程序博客网 时间:2024/05/02 17:16
Wall
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 20496 Accepted: 6725
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.
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.
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
Northeastern Europe 2001
#include <iostream>#include <algorithm>#include <cmath>#include <cstdio>using namespace std;#define PI 3.14159265int n,r;int i,top;double len;struct point { double x, y, angel;} p[1005], ch[1005];double dist (point a, point b) { return sqrt ((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));}double multi (point a, point b, point c) { double x1, y1, x2, y2; x1 = b.x - a.x; y1 = b.y - a.y; x2 = c.x - b.x; y2 = c.y - b.y; return x1*y2 - x2*y1;}bool cmp (point a, point b) { if (a.y == b.y) return a.x < b.x; return a.y < b.y;}bool cmp2 (point a, point b) { if (a.angel == b.angel) { if (a.x == b.x) return a.y > b.y; return a.x > b.x; } return a.angel < b.angel;}void Tubao() { //Graham_Scan算法 ch[0] = p[0], ch[1] = p[1], ch[2] = p[2]; top = 3; for (i = 3; i < n; i++) { while (top > 2 && multi (ch[top-2], ch[top-1], p[i]) <= 0) top--; ch[top++] = p[i]; }}int main() { scanf ("%d%lf", &n, &r); for (i = 0; i < n; i++) scanf ("%lf%lf", &p[i].x, &p[i].y); sort (p, p+n, cmp); //找到左下角的p[0] //找相对于p[0]的极角,并把除了p[0]以外的点按照极角排序 for (i = 1; i < n; i++) p[i].angel = atan2 (p[i].y-p[0].y, p[i].x-p[0].x); sort (p+1, p+n, cmp2); Tubao(); //求周长 len = dist (ch[0], ch[top-1]); for (i = 1; i < top; i++) len += dist (ch[i], ch[i-1]); len += 2 * PI * r; //加上圆弧,刚好为一个圆! printf("%.lf\n",len); return 0;}
- 1113 Wall
- 1113 Wall
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 wall
- PKU 1113 Wall
- poj 1113 Wall
- POJ 1113 wall
- poj 1113 Wall
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113(Wall-Quickhull)
- POJ 1113 Wall
- poj-1113-Wall
- poj 1113 Wall
- 在workspace中可以看这个类的头文件和cpp文件,但是在classview中看不到这个新建的类
- 查看自己的可访问的document目录
- 自定义UISlider的样式和滑块
- apache的作用和tomcat的区别
- oracle 行迁移与行链接(2)
- 1113 Wall
- 心情
- Can’t connect to local MySQL server through socket 解决办法
- testimagetest
- TF-IDF算法简述
- 黑马程序员—数组的反射
- OpenGeoDa:开源空间统计分析软件
- Fundamental I 09 Storage Structure and Relationships
- C++输入输出流总结