Calculate the farthest point of rotation on the card Shell

Source: Internet
Author: User
Struct point {int X, Y; point () {} Point (int xx, int YY) {x = xx; y = YY;} point operator-(point const & B) const {return point (x-b.x, y-b.y);} int friend operator * (point a, point B) {return f_abs (. x * B. y-a.y * B. x) ;}int len2 () {return x * x + y * y ;}}; /* ===================================================== ===============* \ | rotating_calipers rotating the card shell O (N) | call: res = Graham (PNT, n); RES is the farthest point Distance Square; \ * =================================================== ============= */INT rotating_calipers (point PNT [], int N) {int q = 1, ANS = 0, I; for (I = 0; I <n; I ++) {While (PNT [(I + 1) % N]-PNT [I]) * (PNT [(q + 1) % N]-PNT [I])> (PNT [(I + 1) % N]-PNT [I]) * (PNT [Q]-PNT [I]) q = (q + 1) % N; ans = f_max (ANS, f_max (PNT [I]-PNT [Q]). len2 (), (PNT [(I + 1) % N]-PNT [(q + 1) % N]). len2 ();} return ans ;}
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.