Poj2187 beauty contest rotating case

Source: Internet
Author: User
First obtain the convex hull, and then rotate the card shell to output the square beauty contest of the farthest point.
Time limit:3000 Ms   Memory limit:65536 K
Total submissions:24459   Accepted:7467

Description

Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the title 'Miss cow world '. as a result, Bessie will make a tour of N (2 <= n <= 50,000) farms around the world order to spread goodwill between farmers and their
Cows. for simplicity, the world will be represented as a two-dimen1_plane, where each farm is located at a pair of integer coordinates (x, y ), each having a value in the range-10,000... 10,000. no two farms share the same pair of coordinates.

Even though Bessie travels directly in a straight line between pairs of farms, the distance between some farms can be quite large, so she wants to bring a suitcase full of hay with her so she has enough food to eat on each leg of her journey. since Bessie refills
Her suitcase at every farm she visits, she wants to determine the maximum possible distance she might need to travel so she knows the size of suitcase she must bring. help Bessie by computing the maximum distance among all pairs of farms.

Input

* Line 1: A single integer, n

* Lines 2. n + 1: two space-separated integers x and y specifying coordinate of each farm

Output

* Line 1: A single integer that is the squared distance between the pair of farms that are farthest apart from each other.

Sample Input

 
40 00 11 11 0

Sample output

 
2

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <string> # include <vector> using namespace STD; const int maxn = 100; const double EPS = 1e-8; const double Pi = ACOs (-1.0); inline double sqr (Double X) {return x * X ;} int gcd (int A, int B) {return B = 0? A: gcd (B, A % B);} int sig (Double X) {If (FABS (x) <EPS) return 0; If (x> 0) return 1; return-1 ;}struct point {Double X, Y; point () {}; point (double A, double B): X (A), y (B) {} void input () {scanf ("% lf", & X, & Y);} friend point operator + (const point & A, const point & B) {return point (. X + B. x,. Y + B. y);} friend point operator-(const point & A, const point & B) {return point (. x-b.x,. y-b.y);} friend bool operator = (const point & A, const point & B) {return sig (. x-b.x) = 0 & sig (. y-b.y) = 0;} friend point operator * (const point & A, const double & B) {return point (. x * B,. y * B);} friend point operator * (const double & A, const point & B) {return point (A * B. x, a * B. y);} friend point operator/(const point & A, const double & B) {return point (. x/B,. y/B);} double norm () {return SQRT (sqr (x) + sqr (y) ;}; double det (const point &, const point & B) {return. x * B. y-a.y * B. x;} double dot (const point & A, const point & B) {return. x * B. X +. y * B. y;} double dist (const point & A, const point & B) {return sqr (. x-b.x) + sqr (. the y-b.y);} struct polygon_convex {vector <point> P; polygon_convex (INT size = 0) {P. resize (size);} polygon_convex operator = (polygon_convex) {P. clear (); For (INT I = 0; I <X. p. size (); I ++) p. push_back (X. P [I]); return * This ;}; bool cmp_less (const point & A, const point & B) {return sig (. x-b.x) <0 | sig (. x-b.x) = 0 & sig (. y-b.y) <0;} polygon_convex convex_hull (vector <point> A) {polygon_convex res (2 *. size () + 5); sort (. begin (),. end (), cmp_less);. erase (unique (. begin (),. end (),. end (); int m = 0; For (INT I = 0; I <. size (); I ++) {While (M> 1 & sig (det (res. P [M-1]-res. [m-2], a [I]-res. P [m-2]) <= 0) m --; Res. P [M ++] = A [I];} int K = m; For (INT I = int (. size ()-2; I> = 0; I --) {While (M> K & sig (det (res. P [M-1]-res. [m-2], a [I]-res. P [m-2]) <= 0) m --; Res. P [M ++] = A [I];} res. p. resize (m); if (. size ()> 1) res. p. resize m-1); Return res;} double convex_diameter (polygon_convex & A, Int & first, Int & Second) {vector <point> & P =. p; int n = P. size (); double maxd = 0.0; If (n = 1) {First = Second = 0; return maxd ;}# define next (I) (I + 1) % N) for (INT I = 0, j = 1; I <n; I ++) {While (SIG (det (P [next (I)] -P [I], p [J]-P [I])-det (P [next (I)]-P [I], p [next (j)] -P [I]) <0) J = next (j); double D = dist (P [I], p [J]); If (D> maxd) {maxd = D; first = I, second = J;} d = dist (P [next (I)], p [next (j)]); if (D> maxd) {maxd = D; first = I, second = J ;}return maxd ;}point P; vector <point> A; polygon_convex con; int main () {int N, S, E; while (CIN> N) {. clear (); For (INT I = 0; I <n; I ++) {P. input ();. push_back (p) ;}con = convex_hull (a); cout <(INT) convex_diameter (con, S, e) <Endl ;}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.