Los Angeles .They have to pack their things,including their collection of circles. Each clown uses a rectangular box and packs his/her circles linearly so that each circle touches the bottom of the box.
Five clowns are planning for a trip toThe clowns wants to spend as little as they can on the boxes so they buy ones with the smallest possible size. Given below is the radii of the circles each clown needs to pack.
Find the width of the smallest rectangular box each clown needs to buy and input the sum of the widths of the five rectangles as the answer. (rounded DOWN to the nearest integer).
Details/Assumptions
Circles are arranged linearly and no circle is stacked on top of another.
Size refers to the width or horizontal length of the smallest possible rectangle.
Below is an example of an acceptable way of packing four circles,though it might not be the optimal way ;) .
Explicit examples
For three circles of radii the smallest possible size is
For it is
For it is
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This problem is a bit tricky. Because there are cases that are not easily seen at a first glance.
For two circles with raddi R and r it is easy to find that the horizontal distance between their centers is 2 R r . So it is tempting to conclude that the minimum width of the box required to fit both of them in is 2 R r + R + r . But this doesn't hold when the difference between the circles is large and the smaller circle is completely tucked under the larger one. In that case The minimum width would be the diameter of the larger circle.
Note also that order matters and we will have to compute the width for all permutations of the circles and find the minimum. This is not too bad as the most we would have to search is 8 ! = 4 0 3 2 0 arrangements for a single list of circles.
To solve we just keep track of the center coordinates of the circles by placing the first one at r . and recursively find the width. Then use pythons itertools module to find the permutation with the least size.
Python: