Hubble Space Telescope
Time limit1sMemory limit128 MB
Find the earliest time t between 0 and 100000 that minimizes the largest distance from the star alpha to the other moving stars.
- Level
Medium6 of 10
- Topics
- Binary search, Geometry, Math
- Solved
- No attempts yet
Problem
An astrophysicist observes a spiral galaxy, the Andromeda Galaxy, through the Hubble Space Telescope. He is interested in the motion of stars in the galaxy. Each star moves with constant velocity along a straight line in the telescope's picture. One of the stars is special and is named alpha. He wants to know the moment at which the maximum distance from alpha to the other stars becomes as small as possible.
The picture is a two-dimensional Cartesian plane. Let be the set of stars, and let be the star alpha. Star moves along the trajectory over time , where is its position at time and is its velocity vector. The stars never actually collide: when two of them meet at a point they simply pass through each other.
Given the stars and their velocities, find the time with at which the maximum distance from alpha to the remaining stars is minimized. If several times achieve the same minimum, report the earliest one.
Figure 1 shows an example with stars. Each arrow is a star's velocity vector. In this example the maximum distance from alpha to the other stars is smallest at time .

(a) at time , and (b) at time .
Figure 1. An example.
Input
The input is read from standard input. The first line contains the number of test cases . Each test case starts with a line containing an integer (), the number of stars in . Each of the next lines contains four integers , , , : the position of star at time and its velocity vector , where and . The first of these lines describes alpha (). Two or more stars may share the same position at time .
Output
Write to standard output. For each test case, print on its own line the time in the range at which the maximum distance from alpha () to the other stars is minimized, rounded to exactly four digits after the decimal point.