This page is still under construction.

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

Robot

Time limit1sMemory limit128 MB

Summary
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 nn points (x1,y1),…,(xn,yn)(x_1, y_1), \dots, (x_n, y_n) in the plane. Your goal is to navigate a robot from point (x1,y1)(x_1, y_1) to point (xn,yn)(x_n, y_n).

From its current point (xi,yi)(x_i, y_i), the robot may travel to any other point (xj,yj)(x_j, y_j) that is at most RR units away, at a speed of 11 unit per second. Before it moves, however, the robot must turn until it faces (xj,yj)(x_j, y_j); this turning happens at a rate of 11 degree per second.

Compute the shortest time needed for the robot to travel from point (x1,y1)(x_1, y_1) to (xn,yn)(x_n, y_n). Assume the robot initially faces (xn,yn)(x_n, y_n).

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 0.40.4 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 RR and nn: RR is the maximum distance the robot may travel between points (10≤R≤100010 \le R \le 1000), and nn is the number of points (2≤n≤202 \le n \le 20).

Each of the next nn lines contains two integers; the ii-th of these lines contains xix_i and yiy_i (−1000≤xi,yi≤1000-1000 \le x_i, y_i \le 1000). Every point is distinct.

The end of input is marked by a test case with R=n=−1R = n = -1.

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 (x1,y1)(x_1, y_1) to (xn,yn)(x_n, y_n). If no such trip is possible, print impossible instead.

Examples2

  1. Example 1

    Input
    10 2
    0 0
    7 0
    10 3
    0 0
    7 0
    14 5
    10 3
    0 0
    7 0
    14 10
    -1 -1
    
    Expected output
    7
    71
    impossible
    
  2. Example 2

    Input
    1000 2
    0 0
    3 4
    -1 -1
    
    Expected output
    5