Each of K rockets hits the circle at an angle, and each virus spreads both ways along the circle at its own speed; find the first time every point of the circumference is covered.
Medium7Binary searchIntervalsGeometryMathNo attempts yetTime limit2sMemory limit512 MB
Darth Vader is back to his favourite hobby, destroying planets, or to be precise their population. He has learned that the rebel leadership gathered on a planet named Watooine, so he wants to remove the threat quickly. The Empire is in a deep recession and no Death Star is left, so his plan is to drop several containers of a deadly virus onto the surface of the planet.
The problem is modelled in two dimensions. Watooine is a circle of radius R centred at (0,0). K Empire spaceships each launch one rocket at the same moment, and every rocket flies in a straight line towards (0,0) at the speed of its own ship. A rocket stops the instant it touches the surface. From the point of impact a virus starts spreading along the surface, moving clockwise and counterclockwise at the same rate. Each virus has its own spread speed. A virus travels only along the surface, so it never crosses the interior of the planet to reach the other side.
The planet is completely infected once every point of the surface has been reached by at least one virus. Find how long that takes.
The first line contains T, the number of test cases. Each test case is given as follows. The first line has two integers R, the radius of the planet in meters, and K, the number of spaceships. Each of the next K lines has four integers: the x coordinate of the ship, the y coordinate of the ship, the speed of its rocket, and the spread speed of its virus. Both speeds are given in meters per second, and the spread speed is measured along the surface. No ship lies inside the planet.
1≤T≤100, 1≤R≤1000000, 1≤K≤10000, both coordinates are between −1000000 and 1000000, and both speeds are between 1 and 1000000.
For each test case, print one line with the number of seconds until the planet is completely infected, rounded to exactly four digits after the decimal point.