LA 4728 Square, returns the diameter of a polygon by rotating the jamming method, 4728

Source: Internet
Author: User

LA 4728 Square, returns the diameter of a polygon by rotating the jamming method, 4728

Given some square, let you calculate the square of the maximum distance between these square vertices.



// Returns the square int diameter2 (vector <Point> & points) {vector <Point> p = ConvexHull (points); int n = p. size (); if (n = 1) return 0; if (n = 2) return Dist2 (p [0], p [1]); p. push_back (p [0]); int ans = 0; for (int u = 0, v = 1; u <n; ++ u) {(;;) {int diff = Cross (p [u + 1]-p [u], p [v + 1]-p [v]); if (diff <= 0) {ans = max (ans, Dist2 (p [u], p [v]); if (diff = 0) ans = max (ans, dist2 (p [u], p [v + 1]); break;} v = (v + 1) % n ;}} return ans ;}





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.