"POJ1113" Wall (convex bag)

Source: Internet
Author: User

Topic

Description

Once Upon a time there is a greedy king who ordered he chief Architect to build a wall around the king ' s castle. The King is so greedy, which he would not listen to his Architect's proposals to build a beautiful brick wall with a Perfe CT 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 have used more resources to build the wall than it is absolutely necessary to satisfy Those requirements, then the Architect'll loose his head. Moreover, he demanded Architect to introduce in once a plan of the wall listing the exact amount of resources that is nee Ded to build the wall.

Your task is-to-help poor Architect-to-save his head, by writing a program that'll find the minimum possible length of t He 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 are situated on a flat ground . The Architect has already established a Cartesian coordinate system and have precisely measured the coordinates of all cast Le ' s vertices in feet.

Input

The first line of the input file contains, numbers N and L separated by a space. N (3 <= n <=) is the number of vertices in the King's Castle, and L (1 <= l <=) is the minimal Numbe R 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-numbers XI and Yi separated by a space ( -10000 <= Xi, Yi <= 10000) that represent the coordinates of ITH vertex. All vertices is different and the sides of the castle do not intersect anywhere except for vertices.

Output

Write to the output file, the single number, the represents the minimal possible length of the wall in feet this could be B Uilt around the castle to satisfy King ' s requirements. You must present the integer number of feet to the King, because the floating numbers is not invented yet. However, you must round the result in such a-a, that's it's accurate to 8 inches (1 foot are equal to inches), since th E King would not be tolerate larger error in the estimates.

Sample Input

9 100200 400300 400300 300400 300400 400500 400500 200350 200200 200

Sample Output

1628

The code is as follows:
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <queue>7#include <cmath>8 using namespacestd;9 #defineMAXN 1010Ten  One struct Point A { -     Doublex, y; -Point (Doublex=0,Doubley=0): X (x), Y (y) {} the }; -  - typedef point Vector; - Point P[MAXN]; +  - intn,l; + Const DoublePi=3.1415926535898; A  at DoubleMyabs (Doublex) {returnx<0?-x:x;} -  - Const Doubleeps=1e-Ten; - intDCMP (DoubleX//judging plus or minus and 0 - { -     if(Myabs (x) <eps)return 0; in     Else returnx<0?-1:1; - } toVectoroperator-(point A,point B) {returnVector (a.x-b.x,a.y-b.y);} +  - DoubleDot (Vector a,vector B) {returna.x*b.x+a.y*b.y;} the DoubleCross (Vector a,vector B) {returna.x*b.y-a.y*b.x;} * DoubleLength (Vector A) {returnsqrt (Dot (a,a));} $ Panax Notoginseng  - BOOLCMP (point X,point y) {returnDCMP (x.x-y.x) = =0? (X.Y&LT;Y.Y):(x.x<y.x);} thePoint CH[MAXN];intlen=0; +  A voidcovexhull () the { +      for(intI=1; i<=n;i++) -     { $          while(len>1&&cross (ch[len]-ch[len-1],p[i]-ch[len-1]) <=0) len--; $ch[++len]=P[i]; -}intk=Len; -      for(inti=n-1; i>=1; i--) the     { -          while(Len>k&&cross (ch[len]-ch[len-1],p[i]-ch[len-1]) <=0) len--;Wuyich[++len]=P[i]; the     } -     if(n>1) len--; Wu } -  About Doublepolygonlength () $ { -     DoubleL=0; -      for(intI=2; i<=len;i++) -L+=length (ch[i]-ch[i-1]); AL+=length (ch[1]-Ch[len]); +     returnL; the } -  $ intMain () the { thescanf"%d%d",&n,&l); the      for(intI=1; i<=n;i++) the     { -scanf"%LF%LF",&p[i].x,&p[i].y); in     } theSort (p+1, p+1+n,cmp); the covexhull (); Aboutprintf"%.0f\n", Polygonlength () +pi*l*2); the     return 0; the}
[POJ1113]

2016-04-28 19:32:02

"POJ1113" Wall (convex bag)

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.