This page is still under construction.

Parts of this page are still being built. What you see may change.

Hubble Space Telescope

Time limit1sMemory limit128 MB

Summary
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 nn stars in the galaxy. Each star moves with constant velocity along a straight line in the telescope's picture. One of the nn stars is special and is named alpha. He wants to know the moment at which the maximum distance from alpha to the other n−1n - 1 stars becomes as small as possible.

The picture is a two-dimensional Cartesian plane. Let S={s0,s1,…,sn−1}S = \{s_0, s_1, \dots, s_{n-1}\} be the set of nn stars, and let s0s_0 be the star alpha. Star sis_i moves along the trajectory pi+t vip_i + t\,v_i over time tt, where pi=(xi,yi)p_i = (x_i, y_i) is its position at time 00 and vi=(ai,bi)v_i = (a_i, b_i) 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 tt with 0≤t≤1050 \le t \le 10^5 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 44 stars. Each arrow is a star's velocity vector. In this example the maximum distance from alpha to the other 33 stars is smallest at time t=3t = 3.

(a) at time t=0t = 0, and (b) at time t=3t = 3.

Figure 1. An example.

Input

The input is read from standard input. The first line contains the number of test cases TT. Each test case starts with a line containing an integer nn (2≤n≤500002 \le n \le 50000), the number of stars in SS. Each of the next nn lines contains four integers xix_i, yiy_i, aia_i, bib_i: the position (xi,yi)(x_i, y_i) of star sis_i at time 00 and its velocity vector (ai,bi)(a_i, b_i), where −200000≤xi,yi≤200000-200000 \le x_i, y_i \le 200000 and −500≤ai,bi≤500-500 \le a_i, b_i \le 500. The first of these nn lines describes alpha (s0s_0). Two or more stars may share the same position at time 00.

Output

Write to standard output. For each test case, print on its own line the time in the range 0≤t≤1050 \le t \le 10^5 at which the maximum distance from alpha (s0s_0) to the other n−1n - 1 stars is minimized, rounded to exactly four digits after the decimal point.

Examples1

  1. Example 1

    Input
    5
    4
    6 12 0 -2
    1 8 3 0
    2 1 0 1
    7 4 -1 1
    2
    1000 1000 -1 0
    -1000 -1000 1 0
    5
    0 0 0 0
    -20000 0 10 0
    19990 0 -10 0
    0 19900 0 -10
    0 -19999 0 10
    8
    -621 -213 3 1
    -875 782 1 -4
    584 700 -5 -2
    -12 -628 3 2
    -771 -460 1 3
    676 57 -1 -2
    420 -864 -2 4
    190 -950 -4 5
    2
    -200000 0 2 0
    200000 0 -2 0
    
    Expected output
    3.0000
    1000.0000
    1995.0000
    196.4510
    100000.0000