TopCoder problem "Space3d" used in SRM 16 (Division I Level Three , Division II Level Three)

Problem Statement

Class name: Space3d
Method name: getDensityVolume
Parameters: String[], int
Returns: long

Dr. Bob is a research physicist who deals with matter and anti-matter gases.
Given the physical coordinates of rectangular prism volumes of gases, he needs
to know what the total volume is that has a certain density. Densities are
cumulative, in this sense (i.e, if two identical volumes have densities of 1
each, then that volume has a total density of 2).  The "matter" volumes would
have a positive density, and the "anti-matter" volumes would have a negative
density. A density of zero indicates an empty region.

The String[] will contain elements defining each volume of gas by two x, two y,
two z coordinates, and a density.  For instance, parameters of
"(2,0,1),(5,5,5),1", "(3,3,3),(4,4,4),-1" means that the 3-dimensional region
bounded on two opposite corners by the points (2,0,1) and (5,5,5) has a density
of 1, and the region bounded by (3,3,3) and (4,4,4) has a density of -1. So,
added together, the region (3,3,3)-(4,4,4) has density 0.  Note that quotes are
included only for clarity, and will not be in the Strings in the String[].
Given these Strings and a density to search for, determine the total volume
with exactly this density.

The method signature is:
public long getVolume(String[] al, int density);

In the String[], x, y, and z coordinates are between -1000 and 1000, inclusive.
In the String[], Density is between -10 and 10, inclusive.
The density to find is bounded by -150 <= x <= 150, x != 0.
The String[] will contain between 1 and 15 elements, inclusive.

-Any input that defines a gas with no volume can be ignored (such as
-Any input that defines a gas with no density can be ignored (such as

-If the String[] contains "(0,0,0),(2,2,2),1" "(1,1,1),(3,3,3),1", and density
to search for is 1, the volume with density 1 is the two cubes minus their
intersection = 2*2*2 + 2*2*2 - 1 - 1 = 14.

-If the String[] contains "(0,0,0),(5,5,5),1", "(1,1,1),(4,4,4),-2",
"(2,2,2),(3,3,3),2", and the density to search for is 1, the regions with
density 1 are the unit-thick cubic shell from (0,0,0)-(5,5,5), and the region
(2,2,2)-(3,3,3), for a total of 99.

-If the String[] contains:
with a density to search for of 1, the resulting area is a 2000x2000x2000 cube
one unit thick, but the edges and corners have densities of 2 and 3
respectively, so the returned volume is 23952024.


Parameters:String[], int
Method signature:long getDensityVolume(String[] param0, int param1)
(be sure your method is public)

Problem url:

Problem stats url:




Problem categories: