Burdock Antivirus
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Tests of the burdock antivirus are in full swing. Currently, immunologist scientists are conducting laboratory tests of its effectiveness. The experiment looks as follows:
The experiment takes place on an infinite two-dimensional plane.
At time moment \(t = 0\), two burdock viruses are placed on the plane at points with coordinates (\(x_1\), \(y_1\)) and (\(x_2\), \(y_2\)), and the burdock antivirus is placed at the cell with coordinates (\(x\), \(y\)).
After the start of the experiment, both viruses begin to move in the directions (\(dx_1\), \(dy_1\)) and (\(dx_2\), \(dy_2\)) respectively. This means that the \(i\)-th virus at time moment \(t\) will be located at the point (\(x_i + t \cdot dx_i\), \(y_i + t \cdot dy_i\)).
The antivirus can move across the plane with an arbitrary speed not exceeding \(v\). It can move in any direction and change it arbitrarily. Also, if necessary, it can stay in place.
The task of the antivirus is to destroy both viruses as quickly as possible. Destroying a virus means being at the same point with it at some moment in time. After that, the virus ceases to exist. The antivirus can destroy the viruses in any order.
Your task is to calculate the minimum time in which the antivirus will destroy both viruses.
Input
The first line gives information about the first virus: four integers \(x_1\), \(y_1\), \(dx_1\), \(dy_1\) — its coordinates and direction of movement, respectively.
The second line gives four integers \(x_2\), \(y_2\), \(dx_2\), \(dy_2\) — information about the second virus in the same format.
The third line gives three integers \(x\), \(y\), \(v\) — the coordinates and movement speed of the antivirus.
The speed of the antivirus is strictly greater than the speed of each virus, so the antivirus can always destroy both viruses.
Output
In a single line, output one number — the minimum time in which the antivirus can destroy both viruses.
The answer will be accepted if the absolute or relative error does not exceed \(10^{-7}\).
Constraints
\(-10^6 \le x_1, y_1, x_2, y_2, x, y, dx_1, dy_1, dx_2, dy_2 \le 10^6\),
\(1 \le v \le 10^6\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| -4 0 1 0 4 0 -1 0 -1 0 2 | 3 |
| Input (stdin) | Output (stdout) |
|---|---|
| 6 -5 2 -3 -6 -5 1 1 -3 0 10 | 2.27733751288 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
Burdock Antivirus - Editorial
In this problem two points move, each in some direction and with some speed. We have a point that can move in any direction with a speed not exceeding the given one. We need to catch the two other points with our point.
Since by the statement our speed exceeds the speed of the other two points, we can always catch them. One can show that the following strategy is always optimal: first catch one of the points as fast as possible, then catch the other one. To solve the problem, we try both options for which point to catch first.
Now the problem reduces to the following: we are given our starting point (\(x\), \(y\)), our maximum speed \(v\), the initial position of the point we want to catch (\(x_0\), \(y_0\)), and its velocity vector (\(dx\), \(dy\)). Since we want to catch the point as soon as possible, we move at maximum speed to the point where we meet the target. Let this take time \(t\). Then the meeting happens at the point (\(x_0 + dx \cdot t\), \(y_0 + dy \cdot t\)). This point is valid if the time to get there is exactly \(t\):
\(t = \frac{\sqrt{(x_0 + dx \cdot t - x)^2 + (y_0 + dy \cdot t - y)^2}}{v}\)
Rewriting this condition, we get a quadratic equation:
\(t^2 \cdot (v^2 - dx^2 - dy^2) - 2 \cdot t \cdot (dx \cdot (x_0 - x) + dy \cdot (y_0 - y)) - (x_0 - x)^2 - (y_0 - y)^2 = 0\)
The positive solution of this equation is the time in which we catch the point.
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|