Robot
Time limit1sMemory limit128 MB
Find the shortest travel time for a robot that moves at speed 1 and turns 1 degree per second, hopping between points within distance R.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Bit manipulation, Dynamic programming
- Solved
- No attempts yet
Problem
You are given points in the plane. Your goal is to navigate a robot from point to point .
From its current point , the robot may travel to any other point that is at most units away, at a speed of unit per second. Before it moves, however, the robot must turn until it faces ; this turning happens at a rate of degree per second.
Compute the shortest time needed for the robot to travel from point to . Assume the robot initially faces .
To avoid floating-point precision issues, use the double data type rather than float. It is guaranteed that the unrounded shortest time is no more than away from the nearest integer. If you use inverse trigonometric functions, prefer atan2() over acos() or asin().
Input
The input contains multiple test cases. Each test case begins with a line containing two integers and : is the maximum distance the robot may travel between points (), and is the number of points ().
Each of the next lines contains two integers; the -th of these lines contains and (). Every point is distinct.
The end of input is marked by a test case with .
Output
For each test case, print a single line containing the shortest possible time in seconds (rounded to the nearest integer) required for the robot to travel from to . If no such trip is possible, print impossible instead.