The farthest point in the plane is Time Limit: 3000 MS Memory Limit: 65536 KTotal Submissions: 22454 Accepted: 6868Description. Evaluate the square of the farthest point in the plane of N (2 <= N <= 50,000) points. input * row 1st: N coordinate x and y of the next behavior point, (x, y) (-10,000 <= x, y <= 10,000 integer ). output outputs a row, which is the farthest point to the square. sample Input40 00 11 11 0 Sample Output2Hint (0, 0) a to (1, 1) 2 SourceUSACO 2003 Fall convex hull template question: Use GrahamScan to scan for a convex hull, obviously, the farthest point is on the convex hull. Polar order: sort the point set on the plane to the distance of a point in a counter-clockwise order, so that the point is circled exactly after sorting. (from small to large rows by distance: GrahamScan scan:
This is roughly the case. Supplement: this is a small Bug-it is possible that all points are on a straight line. In this way, we can also find: Ex: a sequence (-) (9, 0), then the st sequence repeats the following operations: (-), () into the queue. () Join, do not turn left-> () queue elements <2 () join ...... [Cpp] # include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <iostream> # include <algorithm> # include <functional> using namespace std; # define MAXN (50000 + 10) double sqr (double x) {return x * x;} struct P {double x, y; P () {} P (double _ x, double _ y): x (_ x), y (_ y) {}} a [MAXN], st [MAXN]; int dis2 (p a, p B) {return sqr (. x-B.x) + sqr (. y-B.y);} double dis (p a, p B) {return sqrt (double (dis2 (A, B);} struct V {double x, y; V () {} V (double _ x, double _ y): x (_ x ), y (_ y) {} V (p a, p B): x (B. x-A.x), y. y-A.y) {}}; double operator * (V a, V B) {return. x * B. y-a.y * B. x;} int cmp (p a, p B) // 1: a> B 0: a <= B {double tmp = V (a [1],) * V (a [1], B); if (tmp> 0) return 1; else if (tmp = 0) return (-(dis (a [1], a)-dis (a [1], B)> 0 )? 1:0; else return 0;} int n; int main () {scanf ("% d", & n); for (int I = 1; I <= n; I ++) cin> a [I]. x> a [I]. y; int p = 1; for (int I = 2; I <= n; I ++) if (a [I]. x <a [p]. x | a [I]. x = a [p]. x & a [I]. y <a [p]. y) p = I; if (p> 1) swap (a [p], a [1]); sort (a + 2, a + 1 + n, cmp ); int size = 1; st [1] = a [1]; for (int I = 2; I <= n ;) if (size <2 | V (st [size-1], st [size]) * V (st [size], a [I])> 0) st [++ size] = a [I ++]; else size --; int ans = 0; for (int I = 1; I <size; I ++) for (int j = I + 1; j <= size; j ++) ans = max (ans, dis2 (st [I], st [j]); cout <ans <endl; return 0 ;}