POJ 2187 N points output 2 points of the maximum distance squared

Source: Internet
Author: User

Rotating Jam

Sample Input

4
0 0
0 1
1 1
1 0
Sample Output

2

1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <string>6# include <cmath>7# include <queue>8# define LLLong Long9 using namespacestd;Ten  One struct Point A { -     intx, y; -Point (int_x =0,int_y =0) the     { -x = _x; y =_y; -     } -Pointoperator-(ConstPoint &b)Const +     { -         returnPoint (x-b.x, Y-b.y); +     } A     int operator^(ConstPoint &b)Const at     { -         returnx*b.y-y*b.x; -     } -     int operator*(ConstPoint &b)Const -     { -         returnx*b.x + y*b.y; in     } -     voidinput () to     { +scanf"%d%d",&x,&y); -     } the }; * //the square of the distance $ intDist2 (point a,point B)Panax Notoginseng { -     return(A-B) * (A-b); the } + //****** two-dimensional convex bag, int*********** A Const intMAXN =50010; the Point LIST[MAXN]; + intStack[maxn],top; - BOOL_cmp (Point p1,point p2) $ { $     intTMP = (p1-list[0]) ^ (p2-list[0]); -     if(tmp >0)return true; -     Else if(TMP = =0&& Dist2 (p1,list[0]) <= Dist2 (p2,list[0])) the     return true; -     Else return false;Wuyi } the voidGraham (intN) - { Wu Point p0; -     intK =0; AboutP0 = list[0]; $      for(inti =1; I < n;i++) -         if(P0.y > List[i].y | | (P0.y = = List[i].y && p0.x >list[i].x)) -         { -P0 =List[i]; AK =i; +         } theSwap (list[k],list[0]); -Sort (list+1, list+n,_cmp); $     if(n = =1) the     { thetop =1; thestack[0] =0; the         return; -     } in     if(n = =2) the     { thetop =2; Aboutstack[0] =0; stack[1] =1; the         return; the     } thestack[0] =0; stack[1] =1; +top =2; -      for(inti =2; I < n;i++) the     {Bayi          while(Top >1&& the((list[stack[top-1]]-list[stack[top-2]]) ^ (list[i]-list[stack[top-2]]) <=0) thetop--; -stack[top++] =i; -     } the } the //rotate Jam to find the maximum distance squared between two points the intRotating_calipers (Point p[],intN) the { -     intAns =0; the Point v; the     intCur =1; the      for(inti =0; I < n;i++)94     { thev = p[i]-p[(i+1)%n]; the          while((v^ (p[(cur+1)%n]-p[cur]) <0) theCur = (cur+1)%N;98ans = max (Ans,max (Dist2 (p[i],p[cur)), Dist2 (p[(i+1)%n],p[(cur+1)%N] )); About     } -     returnans;101 }102 Point P[MAXN];103 intMain ()104 { the     //freopen ("In.txt", "R", stdin);106     intN;107      while(SCANF ("%d", &n) = =1)108     {109          for(inti =0; I < n;i++) the list[i].input ();111 Graham (n); the          for(inti =0; i < top;i++) P[i] =List[stack[i]];113printf"%d\n", Rotating_calipers (p,top)); the     } the     return 0; the}
View Code

POJ 2187 N points output 2 points of the maximum distance squared

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.