PROBLEM LINK:
Author: Yuri Shilyaev
Tester: Hasan Jaddouh
Editorialist: Yury Shilyaev
DIFFICULTY:
Cakewalk
PREREQUISITES:
Mechanics, numbers with floating point.
PROBLEM:
Two players are standing on a straight line at coordinates X_1 and X_2. Their goal is located at coordinate X_3. The first player runs to the goal with speed V_1, the second with V_2. The task is to find, who will came to the goal faster.
QUICK EXPLANATION:
Refresh that the time of route S with velocity v is equal to \frac{S}{v}.
EXPLANATION:
By the formula above, we can find time for the first player t_1 = \frac{S_1}{V_1}, where S_1 = X_3 - X_1. The time for the second player would be t_2 = \frac{S_2}{V_2}, where S_2 = X_2 - X_3. We can already solve the problem by simply comparing t_1 and t_2, but how to determine a ‘Draw’?
As you know, we can’t say that two real numbers are equal in programming language, because of precision. The best way to get rid of floating point numbers is to multiply t_1 and t_2 by V_1 \cdot V_2. The ‘Draw’ happens, when t_1 \cdot V_2 = t_2 \cdot V_1.
AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here.
Tester’s solution can be found here.