Area Between Outer Hull and Inner Hull

Time limit5sMemory limit128 MB

Summary
Compute the convex hull of up to 1000 points twice, removing corner vertices after the first pass, and print the difference of the two polygon areas.
Level

Medium4 of 10

Topics
Geometry, Sorting
Solved
No attempts yet

Problem

You are given a set SS of NN points on the plane, S={(x0,y0),(x1,y1),…,(xN−1,yN−1)}S = \{(x_0, y_0), (x_1, y_1), \dots, (x_{N-1}, y_{N-1})\}.

The outer hull HoH_o of SS is the convex hull of SS. Let PP be the convex polygon of smallest area that contains every point of SS inside it or on its boundary. Then HoH_o is the set of points of SS that are corner vertices of PP. A point of SS that lies on the boundary of PP without being a corner vertex does not belong to HoH_o.

The inner hull HiH_i of SS is the convex hull of S−HoS - H_o, the set left after removing every point of HoH_o from SS.

Compute the area enclosed by HoH_o minus the area enclosed by HiH_i.

A hull with fewer than three corner vertices, and a hull whose points all lie on one straight line, enclose no polygon, so their area is 0. If every point of SS lies on one straight line, both hulls have area 0 and the answer is 0.

Take the set SS of 8 points A(2.0,5.0)A(2.0, 5.0), B(2.0,4.0)B(2.0, 4.0), C(2.0,2.0)C(2.0, 2.0), D(1.0,1.0)D(1.0, 1.0), E(4.0,1.0)E(4.0, 1.0), F(0.0,0.0)F(0.0, 0.0), G(3.0,0.0)G(3.0, 0.0), H(5.0,0.0)H(5.0, 0.0). The outer hull is Ho={F,H,A}H_o = \{F, H, A\}. The point GG lies on segment FHFH but is not a corner vertex, so it drops out. Removing HoH_o from SS leaves S−Ho={B,C,D,E,G}S - H_o = \{B, C, D, E, G\}, and the convex hull of that set is the inner hull Hi={D,G,E,B}H_i = \{D, G, E, B\}. The area of HoH_o is 12.5 and the area of HiH_i is 6.0, so the area between the two hulls is 12.5−6.0=6.512.5 - 6.0 = 6.5.

Input

The input holds several problem sets.

The first line of each problem set has a problem identifier and the point count NN, separated by one space. The identifier is a string of at most 10 characters and contains no whitespace, and 1≤N≤10001 \le N \le 1000. Each of the next NN lines has the xx coordinate and the yy coordinate of one point, separated by one space. Each coordinate is a real number written with at most one digit after the decimal point, and its absolute value is at most 100.0. The same point is never given twice inside one problem set.

The next problem set follows immediately. A line whose identifier is ZZ and whose NN is 0 marks the end of the input. There are at most 100 problem sets.

Output

For each problem set, print one line of the form ProblemID id: area, where id is the identifier given in the input and area is the area between the outer hull and the inner hull. Print the area with 4 digits after the decimal point.

Because every coordinate has at most one digit after the decimal point, the answer is always a multiple of 0.005, so no rounding tie ever comes up.

Examples1

  1. Example 1

    Input
    A1 8
    2.0 5.0
    2.0 4.0
    2.0 2.0
    1.0 1.0
    4.0 1.0
    0.0 0.0
    3.0 0.0
    5.0 0.0
    A2 11
    1.0 5.0
    5.0 5.0
    2.0 4.0
    3.0 4.0
    2.0 3.0
    2.0 2.0
    3.0 2.0
    1.0 1.0
    4.0 1.0
    0.0 0.0
    4.0 0.0
    ZZ 0
    
    Expected output
    ProblemID A1: 6.5000
    ProblemID A2: 14.0000