PC8C - Cave Crisis

no tags 

R2D2 was exploring a tunnel when a cave-in suddenly occurred. Oh no, is he trapped?

Figure1: Overhead view of the cave crisis from the third example test case.

From an overhead view, we can see all the obstacles (debris) on a two-dimensional Cartesian plane. The tunnel is w cm wide, bounded by the lines y = w/2 and y = - w/2. R2D2 starts at (0, 0), and has a perfectly circular footprint of radius r. The exit of the tunnel lies to the right of the line x = 1000. Between R2D2 and the exit lie a number of polygonal obstacles.

Is it possible for R2D2 to navigate between the obstacles and make it to the exit?

Input

The input file will contain multiple test cases. Each test case begins with a single line containing an even integer w (2 ≤ w ≤ 1000), the width of the tunnel, and an integer N (0 ≤ N ≤ 100), the number of obstacles. The next N lines each contain the description of a single obstacle. The i-th obstacle is a simple polygon, specified on a single line containing an integer ni (3 ≤ ni ≤ 10), the number of vertices, followed by ni pairs of integers, xij and yij (0 ≤ xij ≤ 1000 and -w/2 ≤ yijw/2 for j = 1 ... ni), specifying the coordinates of the vertices in counter-clockwise order. Note that obstacles in the input may touch or even overlap. However, you are guaranteed that R2D2's initial location will not touch or overlap any obstacle. The vertices of each polygon are unique, no two non-consecutive edges of the polygon intersect (even at their endpoints), and each polygon is guaranteed to have nonzero area.

The end-of-input is denoted by an invalid test case with w = N = 0 and should not be processed.

Output

For each input test case, you must determine the maximum radius r > 0 that R2D2 could have and still be able to plan a path from his starting location (0, 0) to the tunnel exit without overlapping with any of the obstacles. You should print either this maximum radius r (rounded to two decimal places) or the message "impossible" if no such radius exists.

Example

Input:
6 2
4 2 -1 4 -1 4 1 2 1
3 3 0 6 -1 6 1
8 2
3 1 -1 4 -1 4 4
3 3 -4 6 1 3 1
10 7
4 0 5 4 2 5 3 4 5
3 4 -5 9 -5 9 0
4 8 -5 11 -5 11 -2 8 -2
3 8 3 16 1 11 5
4 21 -5 23 -3 20 -2 15 -4
3 22 3 26 -1 28 0
3 24 0 29 4 25 3
0 0

Output: 
1.00
impossible
1.33

hide comments
Simes: 2024-01-18 08:44:44

Ah ha! Thank you. That's what I was missing!

Oleg: 2024-01-18 01:46:36

It probably looks right. Try also draw a circle in position 0 0 with radius more thatn64.73 - it will overlap with one of obstacles.

Simes: 2024-01-17 17:48:19

Hi @Oleg, so presumably you get 64.73 for this test case?

964 4
10 144 381 121 248 1 265 12 71 101 59 92 53 227 -104 379 -50 480 172 388 233
5 146 -64 171 -284 280 -347 415 -289 328 0
5 351 139 225 -24 338 -75 579 93 456 183
7 119 131 21 -127 123 -207 104 -262 161 -226 328 -48 328 120

Which as per the drawing in my forum post mentioned previously, makes no sense to me. Is my drawing wrong somehow?

Oleg: 2024-01-15 20:49:48

Data seems fine.
Accepted assuming R2D2 in the initial position (0, 0) can't touch any obstacles, but then it can go to negative X coordinates if required.

Simes: 2020-02-20 18:16:52

I think there's a fault in the official test data. See my post in the forum at http://discuss.spoj.com/t/fault-in-pc8c-cave-crisis-test-data/36914.


Added by:Race with time
Date:2010-10-19
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC VB.NET
Resource:ACM Pacific Northwest 2008