Question: http://poj.org/problem? Id = 1113 http://acm.hust.edu.cn/vjudge/contest/view.action? Cid = 22013 # Problem/fwall
Time limit:1000 ms |
|
Memory limit:10000 K |
Total submissions:26219 |
|
Accepted:8738 |
Description
Once upon a time there was a greedy king who ordered his Chief implements ECT to build a wall around the king's castle. the king was so greedy, That he wocould not listen to his own ect'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 shocould not come closer to the castle than a certain distance. if the King finds that the specified ECT has used more resources
To build the wall than it was absolutely necessary to satisfy those requirements, then the same ect will loose his head. moreover, he demanded effecect 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 revoke ECT to save his head, by writing a program that will find the minimum possible length of the wall that he cocould build 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 specified ECT 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
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 T for vertices.
Output
Write to the output file the single number that represents the minimal possible length of the wall in feet that cocould 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 supported Ted 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
Hint
The result is rounded to the nearest integer.
Source
Northeastern Europe 2001:
Give you the coordinates of N points in clockwise order, and then give you a length of L
N points represent the coordinates of the castle,
Require the castle to be at any point to build the city wall at exactly the distance of the city wall, and find the exact length
Note:: Rounding the result to + 0.5 is enough.
Idea: convex hull perimeter + circumference with L as the radius circle
/*************************************** * ******* Accepted220 kb0 MSC ++ 1462 B2013-07-27 15:46:32: give you the coordinates of N points in clockwise order, and then give you the coordinates of the castle. The length of N points represents the coordinates of the castle, and the distance from any point of the castle to the city wall is exactly l far to build the city wall, for exact length, note: the train of thought is to round the result to + 0.5: convex Hull perimeter + circumference with an L radius circle ****************************** * ***************/# include <stdio. h> # include <string. h> # include <math. h ># include <algorithm> using namespace STD; const int maxn = 1000 + 10; const double Pi = 3.1415926535; int N, M; int L; struct point {Double X, Y; point () {} Point (double _ x, double _ y) {x = _ x; y = _ y ;} point operator-(const point & B) const {return point (x-B.x, y-B.y) ;}} P [maxn], CH [maxn]; bool CMP (point a, point B) {if (. X = B. x) return. Y <B. y; return. x <B. x;} double dist (point a, point B) {return SQRT (. x-B.x) * (. x-B.x) +. y-B.y) * (. y-B.y);} double cross (point a, point B)/** Cross Product */{return. x * B. Y-. y * B. x;} void convexhull ()/** convex hull x/{sort (p, p + N, CMP); M = 0; For (INT I = 0; I <n; I ++) {While (M> 1 & cross (CH [s-1]-ch [m-2], 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 (CH [s-1]-ch [m-2], p [I]-ch [m-2]) <= 0) m --; ch [M ++] = P [I];} If (n> 1) m --;} int solve () {convexhull (); double ans = 0; ch [m] = CH [0];/** boundary Processing */For (INT I = 0; I <M; I ++)/** convex circumference */ANS + = dist (CH [I], CH [I + 1]); ans + = pI * l * 2; /** circle circumference */Return (INT) (ANS + 0.5);/** rounding + 0.5 rounded */} int main () {While (scanf ("% d", & N, & L )! = EOF) {for (INT I = 0; I <n; I ++) scanf ("% lf", & P [I]. x, & P [I]. y); printf ("% d \ n", solve ();} return 0 ;}