Monotone chain convex hull (monotonous chain convex hull)

Source: Internet
Author: User
1 monotone chain convex hull (monotonic chain convex hull) algorithm pseudocode: 2 // input: A point set on the plane P 3 // Point Set P is sorted progressively after X 4 // M indicates a total of a [I = 0... m] points, ANS is the required point; 5 struct p 6 {7 int X, Y; 8 friend int operator <(p a, p B) 9 {10 if (. x <B. x) | (. X = B. X &. Y <B. y) 11 return 1; 12 Return 0; 13} 14} A [M + 10], ANS [M + 10]; 15 // judge whether the third point is on the left or right side of the Line 16 // when Judge (), the return value is less than or equal to 0, which indicates on the right side, we are always looking for 17 double judge (p a, p B, p c) 18 {19 Return (B. x-a.x) * (C. y-a.y)-(C. x-a.x) * (B. y-a.y); 20} 21 // construct the lower convex hull, from left to right, from the following through 22 int k1 = 0; 23 for (INT I = 0; I <m; I ++) // lower convex hull 24 {25 while (K1> 1 & judge (ANS [k1-2], ANS [k1-1], a [I]) <= 0) 26 {27 K1 --; 28} 29 ans [K1 ++] = A [I]; 30} 31 // build the upper convex hull, from right to left, from the above through 32 int k2 = k1; 33 for (INT I = s-1; I> = 0; I --) // upper convex hull 34 {35 while (K1> k2 & judge (ANS [k1-2], ANS [k1-1], a [I]) <= 0) 36 {37 K1 --; 38} 39 ans [K1 ++] = A [I]; 40} 41 K1 --; // minus the start point, because the start point has been entered twice;

Convex Hull: nyoj 78

Monotone chain convex hull (monotonous chain convex hull)

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.