Model Scott’s straight road as the positive $Y$ axis, with Scott starting at the origin. The barricades are line segments, specified by their endpoints. Determine how far Scott can ride, or if his path is completely unobstructed.
The first line of input contains a single integer $n$ ($1 \le n \le 1,000$), which is the number of barricades.
Each of the next $n$ lines contains four integers $x1$, $y1$, $x2$ and $y2$ ($-100 \le x1,y1,x2,y2 \le 100$, $x1 \ne 0$, $x2 \ne 0$), representing a barricade that runs from $(x1,y1)$ to $(x2,y2)$. It is guaranteed that no barricade will run through the origin.
Output a single real number, which is how far Scott can ride before he hits the closest barricade, or $-1.0$ if no barricades get in Scott’s way. This output will be considered correct if it is within an absolute or relative error of $10^{-2}$.
Sample Input 1 | Sample Output 1 |
---|---|
2 -10 7 5 19 -1 -1 8 21 |
1.4444444444444446 |
Sample Input 2 | Sample Output 2 |
---|---|
2 4 -6 -12 -1 3 5 8 8 |
-1.0 |