Moving Points

Time limit1sMemory limit128 MB

Summary
Find the least time for one chaser to intercept N moving targets in order when the chaser is faster than every target.
Level

Medium7 of 10

Topics
Dynamic programming, Geometry, Greedy, Bit manipulation
Solved
No attempts yet

Problem

Several target points move in a plane. Each target point travels along a straight line at a constant speed and never changes direction. A single chaser point starts at the origin (0,0)(0, 0) and moves at a constant speed that is strictly greater than the speed of every target point. Unlike the targets, the chaser may change direction instantly at any moment.

The chaser catches a target the instant they occupy the same point in the plane at the same time; contact may be momentary, so the chaser does not need to stay with a target for any positive length of time. After catching one target, the chaser continues on to catch another, and so on, until every target has been caught.

Given the chaser's speed and the initial position, heading, and speed of each target, find the minimum total time the chaser needs to catch all of the targets.

Input

The input contains several test cases. Each test case begins with a line holding two integers:

N C

where NN (1≤N≤151 \le N \le 15) is the number of target points and CC (0<C≤10000 < C \le 1000) is the speed of the chaser.

Each of the next NN lines describes one target with four integers:

X Y D S

where (X,Y)(X, Y) (−1000≤X,Y≤1000-1000 \le X, Y \le 1000) is the position of that target at time 00, DD (0≤D<3600 \le D < 360) is its heading in degrees (00 degrees points along the positive xx-axis and 9090 degrees along the positive yy-axis), and SS (0≤S<C0 \le S < C) is its speed. Every target begins moving at time 00.

The input ends with a line containing two zeros: 0 0.

Output

For each test case, print on its own line the minimum time the chaser needs to catch every target, rounded half up to two decimal places and always shown with exactly two digits after the decimal point. Print no extra spaces and do not separate answers with blank lines.

Examples1

  1. Example 1

    Input
    2 25
    19 19 32 10
    6 45 133 19
    5 10
    10 20 45 3
    30 10 135 4
    100 100 219 5
    10 100 301 4
    30 30 5 3 
    0 0
    
    Expected output
    12.62
    12.54