3D Printer

Time limit1sMemory limit128 MB

Summary
Compute the union volume of up to 100 non-overlapping convex polyhedra given by their polygonal faces.
Level

Medium7 of 10

Topics
Geometry, Math, Implementation, Divide and conquer
Solved
No attempts yet

Problem

3D printing manufactures items from a digital template. The printer lays down layers of a polymer material, building an entire 3D object as a series of flat plates of varying shapes stacked upon one another. The polymer is initially sticky enough that plates printed on top of one another adhere; after the object dries or cures, the result can be quite durable.

Consider a 3D printer whose objects are described by a template consisting of several convex polyhedra (flat-surfaced objects such that a line from one interior point to another interior point never passes outside the volume of the object). Write a program that determines the total volume of polymer required to sculpt an object from a given template.

Input

The input contains several test cases. Each test case begins with a line containing a single integer nn (1≤n≤1001 \le n \le 100), the number of polyhedra in that template.

The following lines describe the nn polyhedra. Each polyhedron begins with a line containing an integer ff (3<f<303 < f < 30), the number of its faces. That line is followed by ff lines describing the polygons that form the faces. Each such line begins with an integer vv (3≤v≤243 \le v \le 24), the number of vertices, followed on the same line by 3v3v real numbers giving the vv vertices as (x,y,z)(x, y, z) coordinates. For example, when v=3v = 3 the line is:

v x1 y1 z1 x2 y2 z2 x3 y3 z3

All coordinates lie in the range [−100,100][-100, 100]. Vertices are listed in sequential order: the polygon has an edge from (x1,y1,z1)(x_1, y_1, z_1) to (x2,y2,z2)(x_2, y_2, z_2), from (x2,y2,z2)(x_2, y_2, z_2) to (x3,y3,z3)(x_3, y_3, z_3), and so on. Polygons are closed, so there is an implied edge from the last vertex of a polygon back to the first. All vertices of a face are coplanar, edges do not cross, and each vertex lies on exactly two edges. No three or more vertices of a polygon are collinear.

No two polyhedra within a test case overlap. The input ends with a line containing a single 00.

Output

For each template, print on its own line the volume of polymer required, in cubic centimeters. Print the volume rounded to exactly two decimal places. Do not print any spaces, and do not print any blank lines between answers.

Examples1

  1. Example 1

    Input
    2
    6
    4 10 10 0 10 15 0 15 15 0 15 10 0
    4 10 10 0 10 15 0 10 15 20 10 10 20
    4 10 15 0 15 15 0 15 15 20 10 15 20
    4 15 15 0 15 10 0 15 10 20 15 15 20
    4 10 10 0 15 10 0 15 10 20 10 10 20
    4 10 10 20 10 15 20 15 15 20 15 10 20
    6
    4 0 0 0 0 25 0 25 25 0 25 0 0
    4 0 0 0 0 25 0 0 25 0.5 0 0 0.5
    4 0 25 0 25 25 0 25 25 0.5 0 25 0.5
    4 25 25 0 25 0 0 25 0 0.5 25 25 0.5
    4 25 0 0 0 0 0 0 0 0.5 25 0 0.5
    4 0 0 0.5 0 25 0.5 25 25 0.5 25 0 0.5
    0
    
    Expected output
    812.50