HDU 1348 (convex bag)

Source: Internet
Author: User
Tags integer numbers

Wall

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4903 Accepted Submission (s): 1419


Problem Descriptiononce Upon a time there was a greedy King who ordered he chief Architect to build a wall around the Kin G ' 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.

Inputthe first line of the input file contains the integer 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.

Outputwrite to the output file, the single number, the represents the minimal possible length of the wall in feet that Coul D 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 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.

This problem contains multiple test cases!

The first line of a multiple input was an integer N and then a blank line followed by N input blocks. Each input block was in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Sample Input19 100200 400300 400300 300400 300400 400500 400500 200350 200200 200

Sample Output1628

Source Northeastern Europe 2001 test Instructions: The King is going to fix an outer wall outside the castle, and this outer wall will be at least m feet across the castle, and the minimum cost of repairing the exterior wall is required.
Analysis: We first need to find an outer wall that just covers the entire castle, where the convex hull algorithm is used, and the perimeter of a circle is added, and the Graham algorithm is used here. Here is the algorithm flow: make P0 the smallest point in Q y-x (not X-y) coordinates
Set <p1, p2,... pm> a set of points that are sorted counterclockwise for the rest of the points by P0, if there are multiple points with the same polar angle, all except the point farthest away from P0
pressure p0 into the stack s
pressure P1 into the stack s
pressure P2 into the stack s
For i←3 to M
does while the next element of the top element of S's stack, the top element of S stack, and the folded segment of Pi do not turn to the left
on the S-Bomb stack
pressure pi into the stack s
return S;
#include <stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>using namespacestd;Const intN =1005;Const DoublePI = Atan (1.0)*4;Const DoubleEPS = 1e-8;structpoint{Doublex, y;} P[n]; Point Stack[n]; ///simulation Stack, otherwise the second element of the stack is not good to handleDoublemult (Point a,point b,point c) {return(a.x-c.x) * (B.Y-C.Y)-(b.x-c.x) * (a.y-c.y);}DoubleDis (point a,point b) {return(a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y);}intn,m;intCMP (Point A,point B)///Set<p1,p2,... pm>a set of points that are sorted counter-clockwise to the rest of the points by P0-centric (if there are multiple points with the same polar angle, except for all the points farthest from P0){    if(Mult (a,b,p[0]) >0)        return 1; if(Mult (a,b,p[0])==0&&dis (b,p[0])-dis (a,p[0]) >EPS)return 1; return 0;}intGraham () {inttop=2;///stack top at 2, because the first two points of the convex hull are not changedSort (p+1, p+n,cmp); stack[0]=p[0];///pressure p0p1p2 into the stack sstack[1]=p[1]; stack[2]=p[2];  for(intI=3; i<n;i++){         while(top>=1&&mult (p[i],stack[top],stack[top-1]) >=0){///with a better choice .top--; } stack[++top]=P[i]; }    returntop;}intMain () {inttcase; scanf ("%d",&tcase);  while(tcase--) {scanf ("%d%d",&n,&m);  for(intI=0; i<n; i++) {scanf ("%LF%LF",&p[i].x,&p[i].y); }        intK =0;  for(intI=0; i<n; i++)///make P0 the smallest point in the Q-y-x coordinate order        {            if(p[k].y>p[i].y| | ((P[K].Y==P[I].Y) && (p[k].x>p[i].x)))  {k=i; }} swap (p[0],p[k]); Doublesum=0; inttop =Graham ();  for(intI=1; i<=top;i++) {sum+=sqrt (DIS (stack[i],stack[i-1])); }        ///handle the last point and P0Sum+=sqrt (DIS (stack[0],stack[top])); ///Plus Circlesum+=2*pi*m; printf ("%.0lf\n", sum); if(tcase) printf ("\ n"); }    return 0;}

HDU 1348 (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.