Poj_2540
Set the previous vertex to P, and the current vertex to C. Obviously, the distance to P is equal to the distance to C on the center vertical line of the online segment PC, this straight line divides the plane into Two Half Planes. If it is hotter, it means that the object is in the half plane closer to C. If it is colder, it means that the object is in the half plane closer to P, as a result, we have transformed this problem into a semi-plane intersection.
# Include <stdio. h>
# Include < String . H>
# Define Maxd 210
# Define INF 10
# Define Zero 1e-8
Struct Point
{
Double X, Y;
} Wa [maxd], WB [maxd], * a, * B;
Int N, Na, NB;
Double Px, Py, CX, Cy;
Char St [ 10 ];
Double FABS ( Double X)
{
Return X < 0 ? -X: X;
}
Int DCMP ( Double X)
{
Return FABS (x) <zero? 0 : (X < 0 ? - 1 : 1 );
}
Double Det ( Double X1, Double Y1, Double X2, Double Y2)
{
Return X1 * Y2-X2 * Y1;
}
Void Init ()
{
Int I, J, K;
A = wa, B = WB;
A [ 0 ]. X = 0 , [ 0 ]. Y = 0 , [ 1 ]. X = inf, [ 1 ]. Y = 0 , [2 ]. X = inf, [ 2 ]. Y = inf, [ 3 ]. X = 0 , [ 3 ]. Y = inf;
A [Na = 4 ] = [ 0 ];
Px = py = 0 ;
}
Void Add ( Double X, Double Y)
{
B [Nb]. x = X, B [Nb]. Y = y;
++ NB;
}
Void Cut ( Double X0, Double Y0, Double NX, Double NY)
{
Int I, J, K;
Point * t;
Double T1, T2, X, Y;
NB = 0 ;
For (I = 0 ; I <Na; I ++)
{
T1 = det (NX, NY, a [I]. X-x0, a [I]. Y-y0 );
T2 = det (NX, NY, a [I + 1 ]. X-x0, a [I + 1 ]. Y-y0 );
If (DCMP (T1)> = 0 )
Add (A [I]. X, a [I]. y );
If (DCMP (T1) * DCMP (T2) < 0 )
{
X = (FABS (T2) * A [I]. x + FABS (T1) * A [I + 1 ]. X)/(FABS (T1) + FABS (T2 ));
Y = (FABS (T2) * A [I]. Y + FABS (T1) * A [I + 1 ]. Y)/(FABS (T1) + FABS (T2 ));
Add (x, y );
}
}
T = A, A = B, B = T;
A [Na = Nb] = [ 0 ];
}
Void Calculate ()
{
Int I, J, K;
Double S = 0 ;
For (I = 0 ; I <Na; I ++)
S + = det (A [I]. X, a [I]. Y, a [I + 1 ]. X, a [I + 1 ]. Y );
Printf ( " %. 2lf \ n " , FABS (s )/ 2 );
}
Void Solve ()
{
Int I, J, K;
If (St [ 0 ] = ' S ' )
NA = 0 ;
Else If (St [ 0 ] = ' H ' )
Cut (PX + cx )/ 2 , (PY + cy )/ 2 , Cy-py, PX-cx );
Else
Cut (PX + cx )/ 2 , (PY + cy )/ 2 , Py-cy, CX-Px );
Calculate ();
}
Int Main ()
{
Init ();
While (Scanf ( " % Lf % s " , & CX, & cy, St) = 3 )
{
Solve ();
Px = Cx, Py = Cy;
}
Return 0 ;
}