This page is still under construction.

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

About Love...

Time limit2sMemory limit1024 MB

Summary
Two moving line segments drift at constant velocities; find the earliest time they touch, or report -1 if they never do.
Level

Hard8 of 10

Topics
Geometry, Binary search, Math, Implementation
Solved
No attempts yet

Problem

A spider and a spideress are floating across a lake on two twigs. They cannot swim, so they can meet only when the twigs touch.

Assume the twigs are line segments and move at constant velocities. Determine how long the unfortunate arthropods must wait to meet.

Input

The input file contains 12 numbers: x1x_1, y1y_1, x2x_2, y2y_2, x3x_3, y3y_3, x4x_4, y4y_4, v1xv_{1x}, v1yv_{1y}, v2xv_{2x}, v2yv_{2y}. The endpoints of the first segment are (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2), the endpoints of the second segment are (x3,y3)(x_3, y_3) and (x4,y4)(x_4, y_4), the velocity of the first segment is (v1x,v1y)(v_{1x}, v_{1y}), and the velocity of the second segment is (v2x,v2y)(v_{2x}, v_{2y}). All numbers are integers with absolute value at most 10410^4. At the initial moment the twigs do not touch.

It is guaranteed that the twigs have nonzero length.

Output

Print the time until the earliest moment when the twigs touch, with an error of at most 10−410^{-4}. If the twigs never touch, print −1-1.

Examples2

  1. Example 1

    Input
    0 0 -1 3
    4 4 7 7
    3 0
    0 -1
    
    Expected output
    1.6
    
  2. Example 2

    Input
    0 0 -1 3
    4 4 7 7
    1 0
    0 -3
    
    Expected output
    -1