Poj_1474
For a brief introduction to semi-flat transactions, refer to this blog: http://blog.csdn.net/accry/article/details/6070621. In addition, this blog introducesProgramIt's just a better understanding of O (N ^ 2 ).AlgorithmFor the O (nlogn) algorithm, refer to Zhu zeyuan's paper.
This topic indicates that the points on the polygon are given in clockwise order, so you no longer need to unify each group of data into a certain order.
In poj, the question INF should not be too large. For example, 0x3f3f3f3f will wa, but it will be okay in zoj. The problem of geometric accuracy is too mysterious, so I had to grasp the scale myself.
# Include <stdio. h>
# Include < String . H>
# Define Maxd 210
# Define Zero 1e-8
# Define INF 100000
Struct Point
{
Double X, Y;
} P [maxd], wa [maxd], WB [maxd], * a, * B;
Int N, Na, NB;
Double Det ( Double X1, Double Y1, Double X2, Double Y2)
{
Return X1 * Y2-X2 * Y1;
}
Double FABS ( Double X)
{
Return X < 0 ? -X: X;
}
Int DCMP ( Double X)
{
Return FABS (x) <zero? 0 : (X <0 ? - 1 : 1 );
}
Void Init ()
{
Int I, J, K;
For (I = 0 ; I <n; I ++)
Scanf ( " % Lf " , & P [I]. X, & P [I]. y );
P [N] = P [ 0 ];
}
Void Add ( Double X, Double Y)
{
B [Nb]. x = X, B [Nb]. Y = y;
++ NB;
}
Void Cut ( Int K)
{
Int I, j, NT;
Point * t;
Double X, Y, T1, T2;
NB =0 ;
For (I = 0 ; I <Na; I ++)
{
T1 = det (P [K + 1 ]. X-P [K]. X, P [K + 1 ]. Y-P [K]. Y, a [I]. X-P [K]. X, a [I]. Y-P [K]. y );
T2 = det (P [K + 1 ]. X-P [K]. X, P [K + 1 ]. Y-P [K]. Y, a [I + 1 ]. X-P [K]. X, a [I + 1 ]. Y-P [K]. y );
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;
Nt = Na, na = Nb, NB = Nt;
A [Na] = [ 0 ];
}
Void Solve ()
{
Int I, J, K;
A = wa, B = WB;
NA = 4 ;
A [ 0 ]. X =-INF, [ 0 ]. Y =-INF, [ 1 ]. X =-INF, [ 1 ]. Y = inf, [2 ]. X = inf, [ 2 ]. Y = inf, [ 3 ]. X = inf, [ 3 ]. Y =-INF;
A [Na] = [ 0 ];
For (I = 0 ; I <n; I ++)
Cut (I );
If (NA = 0 )
Printf ( " Impossible. \ n " );
Else
Printf ( " Possible. \ n " );
}
Int Main ()
{
Int T = 0 ;
For (;;)
{
Scanf ( " % D " , & N );
If (! N)
Break ;
Init ();
Printf ( " Floor # % d \ nsurveillance is " , ++ T );
Solve ();
Printf ( " \ N " );
}
Return 0 ;
}