Poj 1113 wall (convex hull)

Source: Internet
Author: User
Tags integer numbers
Wall
Time limit:1000 ms   Memory limit:10000 K
Total submissions:21502   Accepted:7048

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 role ECT has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the role 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 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 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

The answer to the northeastern Europe 2001 question is to add a circle perimeter to the circumference of the convex bag, that is, a rounded polygon surrounded by the convex bag, but I don't know why the rounded corners add up to a circle. Each rounded corner is the center of the vertex corresponding to the convex hull, and the given L is the radius. It is an arc between the tangent points of the two adjacent edges. The angle between the two radius of each arc is complementary to the inner angle of the corresponding convex hull. Assuming that the convex hull has n sides, the sum of all arc angles is 180 ° * n-180 ° * (n-2) = 360 °. Therefore, the perimeter of the wall is = N line segments parallel to the convex hull + the length of N arcs = the circumference of the convex hull + the circumference of the wall from the castle to the radius of L. Program The following is a self-written convex bag template, Graham. The details are modified.
# Include <stdio. h> # Include <Math. h> # Include <Algorithm> # Include <Iostream>Using   Namespace  STD;  Const   Int Maxn = 1000  ;  Const   Double Pi = ACOs (- 1.0  );  Struct  Point {  Int  X, Y ;}; point list [maxn];  Int Stack [maxn], top;  Int Cross (point P0, Point P1, point P2) //  Calculate the cross product p0p1 x p0p2  {  Return (P1.x-Snapshot X) * (p2.y-Snapshot y)-(p1.y-Snapshot y) * (p2.x- Optional X );}  Double DIS (point P1, point P2) //  Calculate the P1P2 distance  {  Return SQRT (( Double ) (P2.x-p1.x) * (p2.x-p1.x) + (p2.y-p1.y) * (p2.y-P1.y ));}  Bool CMP (point P1, point P2) //  The polar ordering function. If the angle is the same, the distance is smaller than the previous one.  {  Int TMP = cross (list [ 0  ], P1, P2 );  If (TMP> 0 ) Return   True  ;  Else   If (TMP =0 & DIS (list [ 0 ], P1) <DIS (list [ 0 ], P2 )) Return   True  ;  Else   Return   False  ;}  Void Init ( Int N) //  Enter and place the vertices at the bottom left of the page in list [0]. And performs polar sorting.  { Int  I, K; point P0; scanf (  "  % D  " , & List [ 0 ]. X, & list [ 0  ]. Y); returns x = List [ 0  ]. X; Policy = List [ 0  ]. Y; k = 0  ;  For (I =1 ; I <n; I ++ ) {Scanf (  "  % D  " , & List [I]. X ,& List [I]. y );  If (Optional Y> list [I]. Y) | (Optional Y = list [I]. Y) & (Optional X> List [I]. X) {returns x = List [I]. X; Policy = List [I]. Y; k = I ;}} list [k] = List [ 0 ]; List [  0 ] = P0; sort (list + 1 , List + N, CMP );}  Void Graham ( Int  N ){  Int  I;  If (N = 1 ) {Top = 0 ; Stack [ 0 ] = 0 ;}  If (N = 2  ) {Top = 1  ; Stack [  0 ] = 0  ; Stack [  1 ] = 1  ;}  If (N> 2  ){ For (I = 0 ; I <= 1 ; I ++) stack [I] = I; top = 1  ;  For (I = 2 ; I <n; I ++ ){  While (Top> 0 & Cross (list [stack [Top- 1 ], List [stack [Top], list [I]) <= 0 ) Top --; Top ++ ; Stack [Top] = I ;}}}  Int  Main (){  Int  N, L;  While (Scanf ( "  % D  " , & N, & L )! = EOF) {Init (n); Graham (N );  Double Res = 0 ;  For ( Int I = 0 ; I <top; I ++ ) Res + = DIS (list [stack [I], list [stack [I + 1  ]); Res + = DIS (list [stack [ 0  ], List [stack [Top]); Res + = 2 * PI * L; printf (  "  % D \ n " ,( Int ) (RES + 0.5  ));}  Return   0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.