TopCoder problem "ThePresents" used in TCHS09 Final Round (Division I Level One)



Problem Statement

    

Santa Claus has n small boxes, all of equal size, containing presents for the children. Each box is a A x A x A cube. Santa wants to pack all of the small boxes into a large rectangular box with dimensions length x width x height. Each small box must be placed inside the big box with its sides parallel to the sides of the big box.

Return the maximal possible value of A that will allow Santa Claus to fit all of the small boxes into the big one. Note that A is not necessarily an integer.

 

Definition

    
Class:ThePresents
Method:find
Parameters:int, int, int, int
Returns:double
Method signature:double find(int n, int length, int width, int height)
(be sure your method is public)
    
 

Notes

-The returned value must be accurate to within a relative or absolute value of 1E-9.
 

Constraints

-n will be between 1 and 1,000,000,000, inclusive.
-length, width and height will be between 1 and 1,000,000,000, inclusive.
 

Examples

0)
    
2
2
2
2
Returns: 1.0
There's room for eight 1x1x1 presents in the big box. However, if the presents are larger than 1x1x1, there is only room for one at most.
1)
    
1
12
47
5
Returns: 5.0
Just one present.
2)
    
10
4
2
10
Returns: 2.0
There will be no free space left in the big box.
3)
    
77
146
523
229
Returns: 52.300000000000004

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13731&pm=10279

Writer:

Vasyl[alphacom]

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Simple Search, Iteration