Poj 2079 triangle: returns the maximum triangle of a point set by rotating the card shell.

Source: Internet
Author: User

A point set is given to find the maximum Triangle Area of the vertex in the point set.


We know that the three points of the Triangle must be on the convex hull. After finding the convex hull, we cannot enumerate it. Because N is a large question, the order of magnitude of O (N ^ 3) is required for enumeration, so the practice of rotating the card shell:
First, enumerate the first vertex I of a triangle, initialize the second vertex J = I + 1 and the third vertex K = J + 1, and cycle K, until the first K is found to make cross (I, j, k)> Cross (I, j, k + 1). If K = I, it enters the next loop.
Rotate J and K, update the maximum value before each loop, and fix a J. Similarly, find a k so that cross (I, j, k)> Cross (I, j, k + 1 ). Perform the ++ operation on J and continue the next operation. We know that J = K' (until j, k is rotated (k + 1) % N) or k = I.


Double rotating_calipers (vector <point> & points) {vector <point> P = convexhull (points); int n = P. size (); p. push_back (P [0]); double ans = 0; For (INT I = 0; I <n; ++ I) {Int J = (I + 1) % N; int K = (J + 1) % N; // when area (P [I], p [J], p [k + 1]) <= Area (P [I], p [J], p [k]) Stop rotation // that is, cross (P [J]-P [I], P [k + 1]-P [I])-cross (P [J]-P [I], p [k]-P [I]) <= 0 // according to cross (a, B)-cross (a, c) = cross (A, B-C) // simplify cross (P [J]-P [I], p [k + 1]- P [k]) <= 0 while (K! = I & cross (P [J]-P [I], p [k + 1]-P [k])> 0) k = (k + 1) % N; If (k = I) continue; int KK = (k + 1) % N; while (J! = KK & K! = I) {ans = max (ANS, cross (P [J]-P [I], p [k]-P [I]); While (K! = I & cross (P [J]-P [I], p [k + 1]-P [k])> 0) k = (k + 1) % N; j = (J + 1) % N ;}return ans * 0.5 ;}


Related Article

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.