Hdu_1392
When N = 2, you only need to output the distance between two points, instead of twice the output distance.
As to why we can find the perimeter of a convex bag, we may use the reverse proof method to prove that the rope on the convex bag must pass through, at the same time, we cannot find a better result so that a part of the rope is not on the side length of the convex bag. Therefore, we only need to obtain the convex hull and calculate its perimeter.
I learned Graham.AlgorithmLater debut.
# Include <stdio. h>
# Include < String . H>
# Include <math. h>
# Include <stdlib. h>
# Define Maxd 110
# Define Zero 1e-8
Struct Point
{
Double X, Y;
} P [maxd], Res [maxd];
Int N, P;
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;
}
Int CMP ( Const Void * _ P, Const Void * _ Q)
{
Point * P = (point *) _ p, * q = (point *) _ q;
If (P-> Y = Q-> Y)
Return P-> x <q-> X? - 1 : 1 ;
Return P-> Y <q-> Y? - 1 : 1 ;
}
Double Sqr ( Double X)
{
Return X * X;
}
Void Init ()
{
Int I, J, K;
For (I = 0 ; I <n; I ++)
Scanf ( " % Lf " , & P [I]. X, & P [I]. y );
Qsort (p, n, Sizeof (P [0 ]), CMP );
}
Int Del ( Int Top, Int I)
{
If (DCMP (det (RES [Top]. X-res [Top- 1 ]. X, Res [Top]. Y-res [Top- 1 ]. Y, P [I]. X-res [Top]. X, P [I]. Y-res [Top]. y) < 0 )
Return 1 ;
Return 0 ;
}
Int Graham ()
{
Int I, J, K, mint, Top = 1 ;
Res [ 0 ] = P [ 0 ], Res [ 1 ] = P [ 1 ];
For (I = 2 ; I <n; I ++)
{
While (Top & del (top, I ))
-- Top;
Res [++ top] = P [I];
}
Mint = top;
Res [++ top] = P [n- 2 ];
For (I = N- 3 ; I> = 0 ; I --)
{
While (Top! = Mint & del (top, I ))
-- Top;
Res [++ top] = P [I];
}
Return Top;
}
Void Solve ()
{
Int I;
Double Ans;
If (N = 1 )
Printf ( " 0.00 \ n " );
Else If (N = 2 )
Printf ( " %. 2lf \ n " , SQRT (sqr (P [ 0 ]. X-P [ 1 ]. X) + sqr (P [ 0 ]. Y-P [ 1 ]. Y )));
Else
{
P = Graham ();
Ans = 0 ;
For (I = 0 ; I <p; I ++)
Ans + = SQRT (sqr (RES [I]. X-res [I + 1 ]. X) + sqr (RES [I]. Y-res [I + 1 ]. Y ));
Printf ( " %. 2lf \ n " , ANS );
}
}
Int Main ()
{
For (;;)
{
Scanf (" % D " , & N );
If (! N)
Break ;
Init ();
Solve ();
}
Return 0 ;
}