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
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
12
47
5
Returns: 5.0
Just one present.
10
4
2
10
Returns: 2.0
There will be no free space left in the big box.
77
146
523
229
Returns: 52.300000000000004
9
9
4
1
Returns: 1.0
4
7
3
2
Returns: 1.75
5
9
5
4
Returns: 2.5
757148
167851001
301413357
336971125
Returns: 2808092.7083333335
659598369
160567226
391749388
4890852
Returns: 77493.83494208494
35766291
26239573
473038165
597007
Returns: 58850.232022891265
3615545
326051437
392289611
118341523
Returns: 1606164.7142857143
170427799
37215529
675016434
168544291
Returns: 291095.493955095
683447134
950090227
82426873
116752252
Returns: 237285.27147852146
194041605
706221269
69909135
257655784
Returns: 402587.16250000003
84970744
21417563
37379061
40873981
Returns: 72601.90847457627
8670529
80835681
436291073
653352031
Returns: 1378379.812236287
106923811
374079501
466701607
86546365
Returns: 520277.47009735747
247776868
480572137
222071041
36629217
Returns: 250644.5158013544
366496749
549646417
278840199
119255907
Returns: 367863.0593667546
33557677
379268590
150378796
137583463
Returns: 614697.8768233387
7
267851000
401413356
436971124
Returns: 1.339255E8
3
260567225
491749387
104890851
Returns: 1.04890851E8
1
126239572
573038164
100597006
Returns: 1.00597006E8
3
426051436
492289610
218341522
Returns: 2.13025718E8
3
137215528
775016433
268544290
Returns: 1.37215528E8
900757147
1
1
1
Returns: 0.0010351966873706003
959598362
2
4
4
Returns: 0.003215434083601286
935766290
1
1
3
Returns: 0.0014734774066797642
903615544
1
3
3
Returns: 0.002150537634408602
1
1000000000
1000000000
1000000000
Returns: 1.0E9
1000000000
1
1
1
Returns: 0.0010
1000000000
1000
1000000
1000000000
Returns: 1000.0
1000000000
300000000
454360005
235345346
Returns: 317605.0553306343
100
1
1
1
Returns: 0.2
2
1000000000
1000000000
1000000000
Returns: 5.0E8
3
1000000000
1000000000
1000000000
Returns: 5.0E8
791051928
329346118
890347265
111391486
Returns: 345363.5628394104
1000000000
1000000000
1000000000
1000000000
Returns: 1000000.0
1
2
12
1000000000
Returns: 2.0
1000000000
1
1000000000
999999999
Returns: 1.0
9
1000000000
1000000000
1000000000
Returns: 3.333333333333333E8
897045453
489418186
516484864
534534864
Returns: 531875.4865671642
1
989418186
916484864
934534864
Returns: 9.16484864E8
1000000000
1000000000
999999999
999999999
Returns: 999999.999
1000000000
1000000000
1000000000
1
Returns: 1.0
1000000000
1000000000
999999999
888888888
Returns: 960960.96
5
1000000000
1000000000
1000000000
Returns: 5.0E8
1
987045410
985541354
949516516
Returns: 9.49516516E8