POJ 1113 Wall(凸包周长)
来源:互联网 发布:师洋淘宝店 编辑:程序博客网 时间:2024/05/16 19:48
Wall
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 32285 Accepted: 10951
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 100200 400300 400300 300400 300400 400500 400500 200350 200200 200
Sample Output
1628
输入n,m,给你n个点,用墙把它们全部围起来,且这个墙距离这些点最近为m ,求最小的墙的长度
墙最小长度 = n个点的凸包周长 + 2πm
(原谅我盗了张图,这样就明白最短周长要加2*π*m了)
#include <iostream> //G++#include <cstdio>#include <cstring>#include <stdlib.h>#include <algorithm>#include <queue>#include <map>#include <cmath>#define inf 0x3f3f3f3f#define PI 3.1415926#define N 1001using namespace std;int m;struct Point{ int x, y; int dis;} pt[N], stack[N],p0;int top, tot;int Dis(int x1 ,int y1, int x2, int y2){ return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);}int Cmp_PolarAngel(struct Point p1, struct Point p2, struct Point pb){ int delta = (p1.x - pb.x) * (p2.y - pb.y) - (p2.x - pb.x) * (p1.y - pb.y); if(delta < 0) return 1; if(delta == 0) return 0; return -1;}bool Is_LeftTurn(struct Point p3, struct Point p2, struct Point p1){ int type = Cmp_PolarAngel(p3, p1, p2); if(type < 0) return true; return false;}int cmp(const void *p1, const void *p2){ struct Point *a1 = (struct Point*) p1; struct Point *a2 = (struct Point*) p2; int type = Cmp_PolarAngel(*a1, *a2, p0); if(type < 0) return -1; if(type == 0) { if(a1->dis < a2->dis) return -1; if(a1->dis == a2->dis) return 0; return 1; } return 1;}void Hull(int n){ int k; p0.x = inf; p0.y = inf; for(int i = 0; i < n; i++) { scanf("%d%d", &pt[i].x, &pt[i].y); if(pt[i].y < p0.y ) { p0.y = pt[i].y; p0.x = pt[i].x; k = i; } else if( pt[i].y == p0.y ) { if(pt[i].x < p0.x) { p0.x = pt[i].x; k = i; } } } pt[k] = pt[0]; pt[0] = p0; for(int i = 1; i < n; i++) { pt[i].dis = Dis(pt[i].x, pt[i].y, p0.x, p0.y); } qsort(pt+1, n-1, sizeof(struct Point), cmp); tot = 1; for(int i = 2; i < n; i++) { if(Cmp_PolarAngel(pt[i], pt[i-1], p0)) pt[tot++] = pt[i-1]; } pt[tot++] = pt[n-1]; top = 1; stack[0] = pt[0]; stack[1] = pt[1]; for(int i = 2; i < tot; i++) { while(top >= 1 && Is_LeftTurn(pt[i], stack[top], stack[top - 1]) == false ) { top--; } stack[++top] = pt[i]; }}void Length(){ double sum = 0; for(int i = 0; i <= top; i++) { sum += sqrt(Dis(stack[i].x, stack[i].y, stack[(i + 1) %( top + 1)].x, stack[(i+1) % (top + 1)].y)); } printf("%.0f\n",sum+2*PI*m);}int main(){ int n; while(~scanf("%d%d", &n,&m)) { Hull(n); Length(); } return 0;}
0 0
- poj 1113 Wall(凸包周长)
- POJ 1113 Wall(凸包周长)
- POJ 1113 Wall【凸包周长】
- POJ 1113 Wall (凸包周长)
- POJ 1113 Wall(凸包周长)
- POJ 1113 Wall(凸包 多边形周长)
- POJ 1113 Wall (凸包+求周长)
- POJ--1113[Wall] 凸包周长+圆的周长
- Wall(HDU1348,凸包周长)
- [ACM] hdu Wall (凸包周长)
- POJ1113 Wall(凸包周长)
- POJ 1113 Wall(求凸包周长)
- POJ 1113 Wall (凸包求周长)
- POJ 1113 Wall 凸包求周长
- POJ 1113 Wall (凸包求周长)
- nyoj 226 && hdu HDU 1348 && poj 1113 wall [凸包周长]
- POJ 1113 && HDU 1348 Wall (凸包周长 graham扫描法)
- POJ 1113 WALL (凸包问题)
- 动态规划
- 从第一眼你就会爱上的bootstrap UI资源(下载)。
- 【effective c++读书笔记】【第8章】定制new和delete(2)
- 使用相对路径来写文件地址
- 27. PHP 文件创建/写入
- POJ 1113 Wall(凸包周长)
- crontab FAQ
- 概率思想
- DevExpress v15.1:WPF控件升级(三)
- checkbox复选事件js
- 用正则表达式过滤出html中得 img标签,并且把URL链接给取出来
- NGUI5种点击事件处理,和点透处理
- 《Java设计模式》之抽象工厂模式
- Python学习笔记---理解zip()函数