Trolley (Luogu P1258) [Mathematics]

In short, the gist is: threepovertyPeople (can't afford a three-seater car), have to arrive at the same time. Then throw this mess at you, and let you ask for the fastest time?

You don't know how to be sure I know (Konjac question mark???)

. . . So far, let’s get down to business, how to find the fastest time to arrive at the same time?

Konjac came to post ideas:

Because two people who don't drive have the same speed. Under the requirement that they need to arrive at the same time, it can be confirmed that the total distance between the two is the same , but it is only a question of who takes the bus first and who goes first.

There is the following graph:

                |||——x——|||— —(s-2*x)— —|||——x——|||

(x is A, B takes the car)

At (s-2*x), A rides a car and B walks. At (s-2*x), A gets off the car, and the car goes back to pick up B.

               |||——x——|||— —(s-2*x)——|||——x——|||

                                                             ————> ||| (A’s walking distance)

The route of the car: ———————————>> ||| (The person in the car is A)

                                  | <<—————— ||| (empty car, go back to pick up B)

                                  | ———————————>> ||| (connect B to the end)

                 ———>> || (B’s walking distance)

[Two segments with the same color take the same time]

From walking to being picked up, let B take the time t.

During time t, the car runs (s-2*x)*2+x. And B only walked x.

The equation can be established: ((s-2*x)*2+x)/b=x/a (b is the vehicle speed, a is the walking speed)

x can be found. Knock the code and convert it to x=2*s*a/(3*a+b)

Find the time by t=x/a.

Then output, Over...


Shunfu Konjac's code:

#include<bits/stdc++.h>
using namespace std;
intmain()
{
    double s,a,b;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>s>>a>>b;
    double t,x;
    x=2*s*a*(1.0)/(3*a+b);
    t=x/(a*1.0)+(s-x)/(b*1.0);
    printf("%.6lf",t);
    return 0;
}






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324492816&siteId=291194637