CF701D As Fast As Possible
Solution Sketch
One crucial observation is: all pupils must spend the same amount of time on bus, or the last student to arrive will need a longer time than the optimal solution.
- p = groups to be taken by bus =
(n - 1) / k + 1
- t1 = time on foot
- t2 = time on bus
- t3 = time between the bus drop off one group of students and pick up anther group of students
The diagram for the first two groups can be illustrated as followed:1234--------> t2 * v2 (group 1 on the bus) <-- t3 * v2 (drop off group 1, and then the bus returned) --------> t2 * v2 (group 2 picked up by the bus)-----> (t2 + t3) * v1 (group 2 time on foot)
From the above diagram, one can get 3 equations123t2 * v2 * p - t3 * v2 * (p - 1) = lt1 * v1 + t2 * v2 = l(t2 + t3) * v1 + t3 * v2 = t2 * v2
Solve the equations, you can get t1
, t2
, t3
, where t1 + t2
is the answer.
AC Code
|
|