Under construction

Still being built. Things may change

Star Trappers

Memory limit1024 MB

Summary
Find the minimum perimeter of a polygon with white-star vertices that strictly contains the blue star, or report IMPOSSIBLE.
Level

Medium7 of 10

Topics
Geometry, Dynamic programming, Sorting
Solved
No attempts yet

문제

John and Ada are sitting on the grass above a small hill. It is midnight and the sky is full of stars. From so far away, the sky looks like a 2D plane, and the stars look like points on that plane. Ada loves blue stars. She suddenly notices one while all the other stars in the sky are white. She wants to trap it, so she asks John for help.

Ada tells John the position of the blue star, and John has to trap it. To trap it, John draws a polygon in the sky with his buster sword so that the blue star is strictly inside the polygon (not on its border). The polygon must have the smallest possible perimeter. The vertices of the polygon must be white stars.

Given the positions of the white stars and the blue star, find out whether John can trap the blue star. If he can, find the minimum perimeter of the polygon he uses.

입력

The first line contains TT, the number of test cases. Each test case starts with an integer NN, the number of white stars. The next NN lines each contain two integers XiX_i and YiY_i, the coordinates of the ii-th white star. The last line of each test case contains two integers XsX_s and YsY_s, the coordinates of the blue star.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the minimum perimeter of the polygon that traps the blue star. If John cannot trap the star, output IMPOSSIBLE as yy. An answer is accepted if its absolute or relative error is within 10−610^{-6}.

제한

  • 1≤T≤1001 \le T \le 100.
  • 0≤Xi,Yi≤1060 \le X_i, Y_i \le 10^6 for all ii.
  • 0≤Xs,Ys≤1060 \le X_s, Y_s \le 10^6.
  • No two stars, including the blue star, have the same position.

힌트

In the first test case there are only two white stars, so no polygon can be drawn. In the second test case there are three white stars, so only one polygon (a triangle) can be drawn. As shown in the picture below, the blue star lies inside this triangle. Its perimeter is 5+5+52≈17.0710685+5+5\sqrt{2}\approx 17.071068.

Examples1

  1. Example 1

    Input
    2
    2
    0 0
    5 0
    2 2
    3
    0 0
    5 0
    0 5
    1 1
    
    Expected output
    Case #1: IMPOSSIBLE
    Case #2: 17.071068