// Question: Use two circles to overwrite a polygon and find the center of the two circles (in a certain order) when the maximum area is covered ).
// The polygon is pushed inward to calculate the half plane intersection + the farthest point pair.
// The data here is not big enough. You can use brute force to find the farthest point to 94 ms AC. The Code is as follows:
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <math. h>
# Define eps 1e-8
// Using namespace std;
Const int MAXN = 202;
Struct point {double x, y ;};
Point points [MAXN], p [MAXN], q [MAXN];
Int n;
Double r;
Bool zero (double x)
{
Return x> 0? X <eps: x>-eps;
}
Double xmult (point p1, point p2, point p0)
{
Return (p1.x-Snapshot X) * (p2.y-Snapshot y)-(p2.x-Snapshot X) * (p1.y-Snapshot y );
}
Int same_side (point p1, point p2, point l1, point l2)
{
Return xmult (l1, p1, l2) * xmult (l1, p2, l2)> eps;
}
Point intersection (point p1, point p2, point p3, point p4)
{
Point ret = p1;
Double t = (p1.x-p3.x) * (p3.y-p4.y)-(p3.x-p4.x) * (p1.y-p3.y ))
/(P1.x-p2.x) * (p3.y-p4.y)-(p3.x-p4.x) * (p1.y-p2.y ));
Ret. x + = t * (p2.x-p1.x );
Ret. y + = t * (p2.y-p1.y );
Return ret;
}
Void polygon_cut (int & n, point * p, point l1, point l2, point side)
{
Point pp [2, 1000];
Int m = 0, I;
For (I = 0; I <n; I ++)
{
If (same_side (p [I], side, l1, l2 ))
Pp [m ++] = p [I];
If (! Same_side (p [I], p [(I + 1) % n], l1, l2)
&&! (Zero (xmult (p [I], l1, l2 ))
& Zero (xmult (p [(I + 1) % n], l1, l2 ))))
Pp [m ++] = intersection (p [I], p [(I + 1) % n], l1, l2 );
}
N = 0;
For (I = 0; I <m; I ++)
If (! I |! Zero (pp [I]. x-pp [I-1]. x) |! Zero (pp [I]. y-pp [I-1]. y ))
P [n ++] = pp [I];
If (zero (p [n-1]. x-p [0]. x) & zero (p [n-1]. y-p [0]. y ))
N --;//
// If (n <3) n = 0;
}
Double distance (point p1, point p2)
{
Return sqrt (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y ));
}
Void slove (double dis, int & m)
{
Int I;
For (I = 0; I <n; I ++) p [I] = points [I];
For (I = 0; I <n; I ++)
{
Point side;
Point s = points [I], e = points [(I + 1) % n];
Double xx = s. x-e.x, yy = s. y-e.y;
Double dd = sqrt (xx * xx + yy * yy );
S. x + = dis * (-yy)/dd;
S. y + = dis * (xx)/dd;
E. x + = dis * (-yy)/dd;
E. y + = dis * (xx)/dd;
Side. x = s. x-yy;
Side. y = s. y + xx;
Polygon_cut (m, p, s, e, side );
}
}
Int main ()
{
While (scanf ("% d % lf", & n, & r )! = EOF)
{
Int I, j;
For (I = 0; I <n; I ++)
Scanf ("% lf", & points [I]. x, & points [I]. y );
Int m = n;
Slove (r, m );
// For (I = 0; I <m; I ++) printf ("% lf, % lf \ n", p [I]. x, p [I]. y );
Double dis = 0;
Int s = 0, e = 0;
For (I = 0; I <m; I ++)
{
For (j = 0; j <m; j ++)
If (I! = J)
{
Double temp = distance (p [I], p [j]);
If (temp-dis> eps)
{
Dis = temp;
S = I; e = j;
}
}
}
If (p [s]. x-p [e]. x> eps | zero (p [s]. x-p [e]. x) & p [s]. y>-p [e]. y> eps)
{
Point tt = p [s];
P [s] = p [e];
P [e] = tt;
}
Printf ("%. 10lf %. 10lf %. 10lf %. 10lf \ n ", p [s]. x, p [s]. y, p [e]. x, p [e]. y );
}
Return 0;
}
Author: ssslpk