// Poj 2187 beauty contest convex hull Application
// Question: give you a series of points, and ask for the longest line segment connected by these points ..
// It is obvious that we think of a convex bag, because the longest point must be on the convex bag ..
// It seems that you can directly perform a violent search .. No ..
// Note: N values must be assigned first, and the number of points must be greater than two. Place the subscript of the Convex Point in Sta [] instead of the Convex Point in point [].
# Include <iostream>
# Include <stdio. h>
# Include <algorithm>
# Include <cstdio>
# Include <cmath>
# Define PI ACOs (-1.0)
Using namespace STD;
Typedef double pointper; // coordinate type
# Define pointnum 50005 // maximum number of vertices
# Define prex 1e-11 // used when the coordinate of a vertex is of the real number type
Struct Node
{
Pointper X, Y;
} Point [2, 10001];
Class Polygon
{
Public:
Int sta [pointnum]; // coordinate of the point on the convex hull
Node point [pointnum];
Bool flag [pointnum];
Int top, N, stab; // n indicates the number of reading points, top-1 indicates the number of points on the convex hull, (0 ~~ Top-2) is the coordinates of the vertices on the convex hull. Top-1 and 0 are the first vertices;
Pointper X1, Y1, X2, Y2;
// Add polygon () to CE .. So remove it ..
//{
// Top = 0;
// N = 0;
//}
Static bool CMP (const node & A, const node & B)
{
Return A. x <B. x | A. X = B. X & A. Y <B. Y; // sort by X first, and then by Y.
}
Bool X (INT X1, int Y1, int X2, int Y2, bool f) // if the value of F is true, the vertex on the edge is included.
{
If (f)
Return X1 * y2-x2 * Y1> = 0;
Return X1 x y2-x2 * Y1> 0;
}
Bool X (double X1, double Y1, double X2, double Y2, bool f) // if the value is true, the vertex on the edge is included.
{
If (f)
Return X1 * y2-x2 * Y1> = 0.0 | FABS (x1 * y2-x2 * Y1) <prex;
Return X1 * y2-x2 * Y1> 0.0;
}
Double DIS (node A, Node B)
{
Return SQRT (double) (A. x-b.x) * (A. x-b.x) + (A. y-b.y) * (A. y-b.y )));
}
Void pointselect (bool F); // calculate the vertex on the convex hull. If F is true, the vertex on the edge is included;
Void getpoint (int I, bool F );
Void XY (int I); // auxiliary X () for cross Multiplication
Double Length (); // calculates the perimeter of the convex hull.
Double area (); // calculates the area of the convex hull;
Bool isinpoly (int x, int y, bool F );
Bool isinpoly (Double X, Double Y, bool F );
};
Polygon tubao;
Void polygon: XY (int I)
{
X1 = point [I]. X-point [sta [Top-2]. X;
Y1 = point [I]. Y-point [sta [Top-2]. Y;
X2 = point [sta [Top-1]. X-point [sta [Top-2]. X;
Y2 = point [sta [Top-1]. Y-point [sta [Top-2]. Y;
}
void polygon: getpoint (int I, bool f)
{< br> XY (I );
If (Top = stab | x (x1, Y1, X2, Y2, f)
{< br> sta [top ++] = I;
flag [I] = false;
}< br> else
{< br> top --;
flag [sta [Top] = true;
XY (I);
while (top> stab &&! X (x1, Y1, X2, Y2, f)
{< br> top --;
flag [sta [Top] = true;
XY (I);
}< br> sta [top ++] = I;
flag [I] = false;
}< BR >}< br> void polygon: pointselect (bool f)
{< br> int I;
memset (flag, true, n + 1);
sort (point, point + N, CMP);
sta [0] = 0;
sta [1] = 1;
Top = 2;
flag [1] = false;
stab = 1;
for (I = 2; I getpoint (I, f);
stab = top;
for (I = n-2; I> = 0; I --)
If (flag [I])
getpoint (I, f);
}
Double polygon: length ()
{
Double S = 0.0;
Int I;
For (I = 1; I <top; I ++)
S + = SQRT (1.0 * (point [sta [I]. x-point [sta [I-1]. x) * (point [sta [I]. x-point [sta [I-1]. x) + (point [sta [I]. y-point [sta [I-1]. y) * (point [sta [I]. y-point [sta [I-1]. Y ));
Return S;
}
Double polygon: Area ()
{
Double S = 0.0;
Int I;
For (I = 1; I <top; I ++)
S + = point [sta [I-1]. x * point [sta [I]. y-point [sta [I]. x * point [sta [I-1]. y;
Return FABS (S/2 );
}
Bool polygon: isinpoly (int x, int y, bool f) // int type
{
Int I;
For (I = 1; I <top; I ++)
If (! X (x-point [sta [I-1]. x, Y-point [sta [I-1]. y, (double) point [sta [I]. x-point [sta [I-1]. x, (double) point [sta [I]. y-point [sta [I-1]. y, f ))
Return false;
Return true;
}
Bool polygon: isinpoly (Double X, Double Y, bool f) // Double Type
{
Int I;
For (I = 1; I <top; I ++)
If (! X (x-point [sta [I-1]. x, Y-point [sta [I-1]. y, point [sta [I]. x-point [sta [I-1]. x, point [sta [I]. y-point [sta [I-1]. y, f ))
Return false;
Return true;
}
Int main ()//
{
Int I, J;
While (scanf ("% d", & tubao. N )! = EOF & tubao. N)
{
For (I = 0; I <tubao. N; I ++)
{
Cin> tubao. Point [I]. x> tubao. Point [I]. Y;
}
Tubao. pointselect (1 );
Double;
Double max = 0;
// For (I = 1; I <tubao. Top; I ++) // tubao. Top stores the number of convex packets ..
// Cout <tubao. point [tubao. sta [I]. x <"" <tubao. point [tubao. sta [I]. Y <Endl;
For (I = 1; I <tubao. Top; I ++)
For (j = I + 1; j <tubao. Top; j ++)
{
A = tubao. Dis (tubao. Point [tubao. Sta [I], tubao. Point [tubao. Sta [J]);
If (A> MAX)
Max =;
}
Printf ("%. 0lf \ n", Max * max); // you can find the longest square after reading it for half a day ..
}
Return 0;
}