Problem Statement
You have exactly 150 unit cubes. You also have a small square table. The horizontal surface of the table is divided into a grid of 10x10 unit squares. Let's label the cells of this grid (0,0) through (9,9).
We can now naturally extend the 2-dimensional grid into a 3-dimensional grid of unit cube cells going upwards from the table. Each cell of this grid will have coordinates (x,y,z) with 0 <= x,y <= 9 and with 0 <= z. (Cells with z = 0 touch the surface of the table.)
Place some of your cubes onto the table, as follows:
- Each cube must exactly fill one of the cube cells of the grid defined above.
- The set of cubes must be stable. That is, if you have a cube at (x,y,z+1), you must also have a cube at (x,y,z).
- The total surface area of your creation must be surface. A face of a cube counts as surface if and only if it has a cube on one side and air on the other side.
If there is no solution, return an empty int[]. If your solution consists of cubes (x1,y1,z1), (x2,y2,z2), and so on, return the following int[]: { x1, y1, z1, x2, y2, z2, ... }. If there are multiple solutions, you may construct and return any of them. The order of cubes in your output may be arbitrary.
Definition
- Class:
- CubesOnATable
- Method:
- placeCubes
- Parameters:
- int
- Returns:
- int[]
- Method signature:
- int[] placeCubes(int surface)
- (be sure your method is public)
Notes
- By definition, faces that touch the table do not count as surface.
Constraints
- surface will be between 1 and 500, inclusive.
Examples
5
Returns: {0, 0, 0 }A single cube placed anywhere on the table will have a surface area of 5.20
Returns: {5, 5, 0, 5, 5, 1, 5, 6, 0, 5, 6, 1, 6, 5, 0, 6, 5, 1, 6, 6, 0, 6, 6, 1 }A 2x2x2 cube built from eight unit cubes has surface area 20.25
Returns: {0, 0, 0, 2, 2, 0, 4, 4, 0, 6, 6, 0, 8, 8, 0 }Five completely disjoint unit cubes, each sitting somewhere on the table.32
Returns: {1, 3, 0, 2, 3, 0, 2, 3, 1, 3, 3, 0, 3, 3, 1, 3, 3, 2, 4, 3, 0, 4, 3, 1, 4, 3, 2, 4, 3, 3 }A staircase: four adjacent columns consisting of 1, 2, 3, and 4 cubes.