POJ 1113 Wall Roll Wrapping method to find convex bag

Source: Internet
Author: User

Wall
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 31199 Accepted: 10521

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

Hint

It turns out to be rounded up.

Source

Northeastern Europe 2001
The main topic: given n points and a distance L, the fence distance from any point is greater than or equal to L, the minimum fence length is obtained. Idea: Ask for the convex hull of the N-point and then add the circumference of the circle with L as radius. Because this total circumference is the length of the convex hull plus the length of the arc, no matter how many segments of the arc, the final must be a circle, so add a circle perimeter. My Code:
#include <cstdio>#include<iostream>#include<algorithm>#include<cmath>#defineEPS 1e-8#definePI 3.1415926535897932384626433832795using namespacestd;structpoint{Doublex, y;};Const intMAXN =1005;p oint P[MAXN];intPROCESS[MAXN];intN, l, K;BOOLcmpConstPoint P1,ConstPoint p2) {    return(P1.y = = P2.y && p1.x < p2.x | | P1.y <p2.y);}intSgnDoublex) {    if(Fabs (x) <EPS)return 0; returnX <0? -1:1;}DoubleGet_direction (Point P1, point P2, point P3)//P1P3 Returns a number less than 0 on the left side of P1p2{    return((p3.x-p1.x) * (P2.Y-P1.Y)-(p2.x-p1.x) * (P3.Y-p1.y));}Doubleget_distance (Point p1, point p2) {returnsqrt ((p1.x-p2.x) * (p1.x-p2.x) + (P1.Y-P2.Y) * (P1.Y-p2.y));}voidJarvis ()//The method of volume wrapping to find convex bag{    intCur =0, Optimal;//Optimal saves the optimal point, which is the outermost point, cur is the currentprocess[k++] =0;  for(inti =1; I < n; i++)    {         for(intj =1; J < N; J + +)        {            if(J! =cur) {Optimal=J;  Break; }        }         for(intj =0; J < N; J + +)        {            if(J! = Optimal && cur! = J && sgn (Get_direction (P[cur], p[j], P[optimal]) <=0)            {                if(SGN (Get_direction (P[cur], p[j], p[optimal]) = =0))                {                    if(Get_distance (P[cur], p[j]) >get_distance (P[cur], p[optimal])) Optimal=J; }                ElseOptimal= J;//Strict left            }        }        if(Optimal = =0)             Break; Process[k++] =Optimal; Cur=Optimal; }}intMain () { while(~SCANF ("%d%d", &n, &L)) {k=0;  for(inti =0; I < n; i++) scanf ("%LF%LF", &p[i].x, &p[i].y); Sort (p, p+N, CMP);        Jarvis (); DoubleAns =0;  for(inti =1; I <= K; i++) {ans+ = Get_distance (P[process[i-1]], p[process[i%N]]); } ans+=2* PI *l; printf ("%d\n", (int) (ans +0.5)); }            return 0;}
View Code

POJ 1113 Wall Roll Wrapping method to find 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.