Topic Link:
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_ problem&problem=953
Type: Backtracking
Original title:
Ian's going to California, and him has to the pack his things, including his collection of circles. Given a set of circles, your program must find the smallest rectangular box in which fit. All circles must the bottom of the box. The figure below shows a acceptable packing for a set of circles (although the. particular circles). Note this in a ideal packing, each circle should touch at least one other circle (but you probably figured.
Input
The "a" of input contains a single positive decimal integer n, n<=50. This is indicates the number of lines which follow. The subsequent n lines each contain a series of numbers separated by spaces. The "a" of "each of" is a positive integer m, m<=8, which indicates how many other numbers on That line. The next m numbers on the line are the radii of the circles which must is packed in a single box. These numbers need are not integers.
Output
For all data line of input, excluding the "a" of input containing n, your program must output the size of the Smal Lest rectangle which can pack the circles. Each case should is output on a separate line by itself, with three places after the decimal point. Do isn't output leading zeroes unless the number is less than 1, e.g. 0.543.
Sample Input
3
3 2.0 1.0 2.0
4 2.0 2.0 2.0 2.0
3 2.0 1.0 4.0
Sample Output
9.657
16.000
12.657
The main effect of the topic:
Given n of unequal sizes, you want to put the n circles in a rectangular box, requiring each circle to be tangent to the bottom of the rectangular box. Then find a circle with the smallest length from all the permutations of this n courtyard. As shown in the figure above.
Analysis and Summary:
This problem is to do a more tangled problem, to find all the arrangement is easy, but the need for the length of the circle is tangled, the situation needs to be considered more.
My approach is to create an axis, and then the first circle and the x and Y axes tangent, and then a circle into the axis, only need to save the center of each circle
At the coordinates of the coordinate can be.
Find the horizontal distance from the center of the two circles connected after the axis is placed:
h = r2-r1;
L = sqrt ((R1+R2) ^2-(R1-R2) ^2);
So the x coordinate of the new join circle is the x-coordinate of the circle with the last phase +l