TopCoder problem "MagicBoxes" used in SRM 262 (Division I Level Three)



Problem Statement

    

A certain company has recently introduced a whole line of "magic" boxes. The smallest of these boxes is a 1x1x1 hollow cube. The next size up is a 2x2x2 hollow cube, and so on, each box 1 unit bigger than the previous in all dimensions. However, because the boxes are so fragile, they can be packed neither inside of each other, nor on top of each other

You are to determine how large a set can fit in a certain sized crate. You are told that there is no restriction on the height of the crate, and the boxes may be packed tightly, with no space between them. Your task is, given x and y, representing the dimensions of the floor of the crate, determine the maximum number of boxes that can be safely packed, given that the sizes of the boxes start at 1x1x1 and increase by 1 with each box (no skipping boxes, if you ship a 3x3x3 box, you must also ship a 2x2x2 and a 1x1x1 box).

For example, a 3x5 crate could hold a 3x3x3, a 2x2x2 and a 1x1x1 box with this configuration (as viewed from above):


   ______ ____
  |      |    |
  |      | 2  |
  |  3   |____|
  |      | 1|  
  |______|__|
 

Definition

    
Class:MagicBoxes
Method:biggest
Parameters:int, int
Returns:int
Method signature:int biggest(int x, int y)
(be sure your method is public)
    
 

Constraints

-x and y are both between 1 and 30, inclusive.
 

Examples

0)
    
1
1
Returns: 1
Only one box can be packed in a 1x1 container.
1)
    
2
2
Returns: 1
A 2x2x2 box could be packed into a 2x2 container, but that would leave no room for a 1x1x1 box. Thus we can only pack 1 box, the 1x1x1.
2)
    
10
10
Returns: 5
If we pack a 6x6x6 box, then there will be no room for a 5x5x5 box. Thus, 6x6x6 will not work. However, a 5x5x5 box will leave room for boxes of all other sizes (4x4x4, 3x3x3, 2x2x2, and 1x1x1):

Here each number represents a part of the footprint of a box of the corresponding size.
.555554444
.555554444
.555554444
.555554444
.55555....
.......1..
.333......
.333.22...
.333.22...
..........
3)
    
26
26
Returns: 11

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=932

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7996&pm=932

Writer:

lars2520

Testers:

PabloGilberto , zoidal , schveiguy , Olexiy

Problem categories:

Search