Colliding Traffic

Time limit1sMemory limit128 MB

Summary
Each boat moves at constant velocity; find the earliest time at which some pair comes within distance r, or report that no pair ever does.
Level

Medium7 of 10

Topics
Geometry, Implementation, Math, Brute force
Solved
No attempts yet

Problem

For a boat on a small, constrained body of water, other traffic can be a major hazard. The more traffic there is in the same area, the higher the risk of a collision.

Your job is to monitor traffic and help detect likely collisions before they occur. You have sensors that detect the position, direction, and speed of each boat. Assuming the direction and speed remain constant, determine whether any of the boats will collide. Two boats are considered to collide if they come within a given distance of each other.

Input

The first line of input contains a single integer cc, the number of test cases to follow. Each test case starts with a line containing two numbers, nn, the number of boats, and rr, the collision distance. Two boats are considered to collide if they come within rr metres of each other. There will be no more than 1000 boats. Each boat is described by a line containing four numbers xx, yy, dd, ss. The numbers xx and yy give the current position of the boat as a distance east and north, respectively, from a common origin, and are between −1000-1000 and 10001000, inclusive. The lake is small enough to be modelled as a flat surface. The number dd gives the direction in which the boat is heading in degrees clockwise from north (so east is 9090 degrees). The number ss gives the speed of the boat in metres per second and is between 0.0010.001 and 10001000. Note that rr, xx, yy, dd, and ss are not necessarily integers. The input data is such that the answer will not change if any of the numbers xx, yy, dd, and ss are changed by 10−610^{-6} or less.

Output

For each test case, output a line containing a single integer: the number of seconds, rounded to the nearest second, before any of the boats come within rr metres of each other. If none of the boats ever collide, output the line:

No collision.

Examples1

  1. Example 1

    Input
    2
    2 5
    0 0 90 1
    10 10 180 1
    2 10
    0 0 0 0
    8 8 270 1
    
    Expected output
    6
    2