PivotOJ

Bearly Made It

시간 제한: 2000ms메모리 제한: 512MB출처: BAPC 2017BOJ 15004

문제

Barney the polar has wandered off on an adventure. Lost in thought, he suddenly realizes he has strayed too far from his mother and is stuck on an ice shelf. He can still see her in the distance, but the only way back is by crossing a group of other ice shelves, all of which are perfectly circular. He is very scared, and can not swim. Barney’s mother, getting a little tired of her son’s shenanigans, decides to wait and let him figure this out for himself. Can you help Barney get home? He is in a hurry.

입력

  • The first line of input contains four integers, −106 ≤ xb, yb, xm, ym ≤ 106, where (xb, yb) is Barney’s location and (xm, ym) is the location where Barney’s mom is waiting.
  • The next line contains a single integer 1 ≤ n ≤ 25, the number of ice shelves.
  • After this n lines follow. Each line holds three integers: −106 ≤ xi , yi ≤ 106 and 1 ≤ ri ≤ 106, the coordinates of the center of the shelf and its radius. A shelf consists of all points at distance ri or less to (xi, yi).

Both bears are on a shelf at the start of Barney’s journey home. Shelves can both touch and overlap.

출력

The minimal distance Barney has to travel to be reunited with his mother. The result should have a relative error of at most 10−6.

If there is no way for Barney to make it home, output “impossible”. (Do not worry about Barney’s well-being in this scenario. His mother will swim out to save him.)

힌트

Figure 2: Illustration of the third example input.

예제

예제 1

입력
0 0 6 0
2
1 1 2
5 1 2
출력
6.32455532034

예제 2

입력
0 0 7 0
2
1 1 2
6 1 2
출력
impossible

예제 3

입력
0 0 1 3
3
0 -1 2
4 -1 3
2 3 2
출력
4.269334912857045697
코드를 제출하려면 로그인하세요.