Poj 1755 triathlon

Source: Internet
Author: User

Poj_1755

At first, I thought it was necessary to enumerate three routes, but after I thought about it, I only needed to enumerate two routes, because I could regard the total distance as a fixed value and set it to INF.

In this way, for contestant I, if the first item In x length and the second item in Y length can run faster than any contestant J, then there will be X/V [I] + Y/U [I] + (INF-x-y) /W [I] <X/V [J] + Y/U [J] + (INF-x-y)/W [J], further, it can be converted into A1 * x + A2 * Y + A3 <0, so we can use the semi-plane intersection to check whether the solution is finally solved.

But there are several questions to consider:

The first one is whether A1 and A2 are 0, because this involves the following vector calculation method. If A1 and A2 are not all 0, we do not need to discuss it in detail, in this way, the subsequent operations have no impact. If A1 and A2 are all 0, if A3> = 0, then there is no solution for this set of inequalities, and we can directly output No, if A3 <0, then this inequality is true for any X and Y, so we don't have to use this straight line to cut, and then enumerate the next player J + 1.

The second is the problem of the Initial Feasible domain. We usually only need to take a relatively large rectangle, but this question is not good, because the question itself is subject to restrictions, in other words, we need to select a feasible domain that satisfies the meaning of the question and is large enough. The condition in the question is 0 <x <INF, 0 <Y <INF, 0 <X + Y <INF, so we can take a triangle.

The third is the issue of computing accuracy. At first, it was always wa. Later I saw a person in dicuss saying that division should be used as little as possible during the operation, for example, 1/V-1/u with (u-v)/(V * u) instead, I tried to improve the accuracy, then with the conventional 1e-8 Can AC.

# Include <stdio. h>
# Include < String . H>
# Define Zero 1e-8
# Define Maxd 210
# Define INF 10000
Struct Point
{
Double X, Y;
} Wa [maxd], WB [maxd], * a, * B;
Int N, Na, NB;
Double U [maxd], V [maxd], W [maxd];
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;
For (I = 0 ; I <n; I ++)
Scanf ( " % Lf " , & V [I], & U [I], & W [I]);
}
Void Add ( Double X, Double Y)
{
B [Nb]. x = X, B [Nb]. Y = y;
++ NB;
}
Void Cut ( Double A1, Double A2, Double A3)
{
Int I, J, K;
Point * t;
Double X, Y, T1, T2, X1, Y1, X2, Y2;
NB = 0 ;
If (DCMP (A2) = 0 )
{
X1 = x2 = (-A3)/A1;
If (DCMP (A1) < 0 )
Y1 = inf, y2 = 0 ;
Else
Y1 = 0 , Y2 = inf;
}
Else
{
If (DCMP (A2) < 0 )
X1 = 0 , X2 = inf;
Else
X1 = inf, X2 = 0 ;
Y1 = (-A3-A1 * X1)/A2, y2 = (-A3-A1 * x2)/A2;
}
For (I = 0 ; I <Na; I ++)
{
T1 = det (x2-X1, Y2-Y1, a [I]. X-X1, a [I]. Y-Y1 );
T2 = det (x2-X1, Y2-Y1, a [I + 1 ]. X-X1, a [I + 1 ]. Y-Y1 );
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 ];
}
Int Check ()
{
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 );
If (DCMP (S) = 0 )
Return 0 ;
Return 1 ;
}
Void Solve ()
{
Int I, J, K;
Double A1, A2, A3;
A = wa, B = WB;
For (I = 0 ; I <n; I ++)
{
NA = 3 ;
A [ 0 ]. X = 0 , [ 0 ]. Y = 0 , [ 1 ]. X = inf, [ 1 ]. Y = 0 , [ 2 ]. X = 0 , [ 2 ]. Y = inf;
A [Na] = [ 0 ];
For (J = 0 ; J <n; j ++)
{
If (J = I)
Continue ;
A1 = (W [I]-V [I])/(W [I] * V [I])-(W [J]-V [J]) /(W [J] * V [J]);
A2 = (W [I]-U [I])/(W [I] * U [I])-(W [J]-U [J]) /(W [J] * U [J]);
A3 = inf * (W [J]-W [I])/(W [I] * W [J]);
If (DCMP (A2) = 0 & DCMP (A1) = 0 )
{
If (DCMP (A3) < 0 )
Continue ;
Break ;
}
Cut (A1, A2, A3 );
}
If (J! = N |! Check ())
Printf ( " No \ n " );
Else
Printf ( " Yes \ n " );
}
}
Int Main ()
{
While (Scanf ( " % D " , & N) = 1 )
{
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.