Poj 3384 feng shui

Source: Internet
Author: User

Poj_3384

The question refers to arranging two circles in a polygon so that the areas covered by the two circles are as large as possible (the overlapping part is only counted once) and finding the coordinates of the center of the two circles.

First, inspired by the question poj_3525, we first contract the edges of the convex polygon in R, in this way, a new convex polygon is obtained (each vertex of the new convex polygon can be obtained through semi-plane intersection). Then the center of the two circles must be in this new convex polygon, otherwise, it will intersection an edge of the original convex polygon.

Now the feasible region of the center is found. Under what circumstances will the two circles cover the largest region? We can intuitively see that the closer the two circles are, the larger the overlap is. That is to say, the farther the two circles are, the better. How can we measure the distance? Center! So we get furtherAlgorithmTo enumerate any two vertices of A New convex polygon, and find the two vertices that are farthest from each other.It is the center of two circles. This can be done because the two points on a polygon must be the vertices of a polygon.

In addition, There Is A Faster Algorithm for Finding the two vertices with the farthest distance on a convex polygon. If I remember correctly, it should be a "Rotating jamming shell", but because the data Scope of this question is not big, in addition, the algorithm I used to calculate the semi-plane intersection is O (n ^ 2) (the algorithm for finding the semi-plane intersection with O (nlogn). For details, see the relevant papers of Zhu zeyuan ), therefore, it is acceptable to use the O (N ^ 2) algorithm to calculate the two vertices on a convex polygon that are the farthest apart.

# Include <stdio. h>
# Include < String . H>
# Include <math. h>
# Define Maxd 210
# Define Zero 1e-8
# Define INF 2000
Struct Point
{
Double X, Y;
} P [maxd], wa [maxd], WB [maxd], * a, * B;
Int N, R, Na, NB;
Double Det ( Double X1, Double Y1, Double X2, Double Y2)
{
Return X1 * Y2-X2 * Y1;
}
Int DCMP ( Double X)
{
Return FABS (x) <zero? 0 : (X < 0 ? - 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 );
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;
Double X, Y, T1, T2, dx, Dy;
T1 = SQRT (sqr (P [K + 1 ]. X-P [K]. X) + sqr (P [K + 1 ]. Y-P [K]. y ));
DX = (P [K]. Y-P [K + 1 ]. Y)/T1 * R;
DY = (P [K + 1 ]. X-P [K]. X)/T1 * R;
Point * t;
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 + dx-P [K]. x, a [I]. Y + dy-P [K]. Y );
T2 = det (P [K + 1 ]. X-P [K]. X, P [K + 1 ]. Y-P [K]. Y, a [I + 1 ]. X + dx-P [K]. X, a [I + 1 ]. Y + dy-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;
NA = Nb;
A [Na] = [ 0 ];
}
Void Solve ()
{
Int I, J, K;
Double T, Max, X1, Y1, X2, Y2;
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 );
Max =- 1.0 ;
For (I = 0 ; I <Na; I ++)
For (J = I; j <Na; j ++)
{
T = SQRT (sqr (A [I]. X-A [J]. X) + sqr (A [I]. Y-A [J]. y ));
If (DCMP (t-max)> 0 )
{
X1 = A [I]. X, Y1 = A [I]. Y;
X2 = A [J]. X, y2 = A [J]. Y;
Max = T;
}
}
Printf ( " %. 5lf %. 5lf %. 5lf %. 5lf \ n " , X1, Y1, X2, Y2 );
}
Int Main ()
{
While (Scanf ( " % D " , & N, & R) = 2 )
{
Init ();
Solve ();
}
Return 0 ;
}


Related Keywords:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.