POJ-1113-Wall [using the volume wrap Method for convex hull] [Gift Wrapping]

Source: Internet
Author: User

Wall
Time Limit:1000 MS
Memory Limit:10000 K
Total Submissions:26587
Accepted:8849

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.

Code:

This question is to find a convex hull based on the given points and calculate its perimeter, plus the four extra 1/4 circles, that is, the circumference of a circle.

Gift Wrapping is to tie a rope to a point and wrap around the outermost point.

The key step is

1. Determine a starting point as the starting point

2. determine the next Vertex on the convex hull.

3. If you want to calculate the perimeter, you can put the points on the convex hull into the queue or array and sum the distance in sequence.

This article is very clear about the specific methods and principles.

Click here: Daniel Space Portal

# Include <stdio. h> # include <queue> # include <algorithm> # include <math. h> # include <string. h> # define PI 3.1415926 using namespace std; typedef struct point {int x, y;} point; point v [1005]; int vis [1005], ver; queue <int> q; int cmp (point a, point B) {if (. x <B. x) return 1; else if (. x = B. x) {if (. y <B. y) return 1; return 0;} return 0;} int calc (point a, point B, point c) // Cross Product {return (B. x-a.x) * (c. y-a.y)-(c. x-a.x) * (B. y-. Y);} double dis (point a, point B) {return sqrt (double) (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} double solve () {vis [0] = 1; int in, I, bu; double sum = 0; in = 0; while (1) {bu =-1; for (I = 0; I <ver; I ++) // locate a point not on the convex hull, that is, it is not marked {if (! Vis [I]) {bu = I; break;} if (bu =-1) break; for (I = 0; I <ver; I ++) {if (calc (v [in], v [bu], v [I])> 0 | (calc (v [in], v [bu], v [I]) = 0 & dis (v [in], v [I])> dis (v [in], v [bu]) bu = I;} if (vis [bu]) break; // if no q. push (bu); vis [bu] = true; in = bu; // bu is the point on the next convex bag. Next time, use bu as the root} in = 0; q. push (in); while (! Q. empty () {I = q. front (); q. pop (); sum + = dis (v [I], v [in]); in = I;} return sum;} int main () {int r, I; double ans; while (scanf ("% d", & ver, & r )! = EOF) {for (I = 0; I <ver; I ++) scanf ("% d", & v [I]. x, & v [I]. y); sort (v, v + ver, cmp); ans = 0; memset (vis, 0, sizeof (vis); ans = solve () + PI * r * 2; printf ("%. f \ n ", ans);} 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.