TopCoder problem "PickupBed" used in TCCC06 Round 1A (Division I Level Two)

Problem Statement

    We have a number of 4-foot long pipes that have regular octagonal cross-sections of various sizes. We want to place them in a pickup truck which is 4 feet wide, with the length of each pipe extending across the width of the truck. Each pipe must rest with one of its 8 sides flat on the truck's bed. The front and back sides of the truck are higher than the pipes, so each pipe must fit entirely inside the truck. How long will the truck have to be to hold them all?

  |                                    |
  |                                    | 
  |                   x x x x          |             
  |                 x         x        |         
  |               x             x      |          
  |     x x x   x                 x    |        
  |   x       x x                 x    |   
  | x           x                 x    | 
  | x           x                 x x  |
  | x           x x             x     x| 
  |   x       x     x         x x     x|   
  |     x x x         x x x x     x x  |     
        <--- length of truck --->              

Create a class PickupBed that contains a method length that is given a int[] ht and returns the minimum length of truck that can hold all the pipes. The i-th element of ht gives the height of a pipe when it is resting on one of its sides.



Method signature:double length(int[] ht)
(be sure your method is public)


-A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.


-ht contains between 1 and 8 elements, inclusive.
-Each element of ht is between 1 and 1000, inclusive.


Returns: 15.0
The pipes will lie with their perpendicular sides against each other. Each one will require the full 5 units of the truck's length.
Returns: 17.0
Returns: 10.0
We can put the big one between the 2 little ones. The little ones can fit entirely in the area under the slanted sides of the big one.
Returns: 10.97056274847714

Problem url:

Problem stats url:




PabloGilberto , brett1479 , vorthys , , Olexiy

Problem categories: