题目链接:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=953
类型: 回溯
原题:
Ian's going to California, and he has to pack his things, including his collection of circles. Given a set of circles, your program must find the smallest rectangular box in which they fit. All circles must touch the bottom of the box. The figure below shows an acceptable packing for a set of circles (although this may not be the optimal packing for these particular circles). Note that in an ideal packing, each circle should touch at least one other circle (but you probably figured that out).
Input
The first line of input contains a single positive decimal integer n, n<=50. This indicates the number of lines which follow. The subsequent n lines each contain a series of numbers separated by spaces. The first number on each of these lines is a positive integer m, m<=8, which indicates how many other numbers appear on that line. The next m numbers on the line are the radii of the circles which must be packed in a single box. These numbers need not be integers.
Output
For each data line of input, excluding the first line of input containing n, your program must output the size of the smallest rectangle which can pack the circles. Each case should be output on a separate line by itself, with three places after the decimal point. Do not 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
题目大意:
给定n个大小不等的圆, 要将这n个圆排进一个矩形框中,要求各个圆都要与矩形框的底边相切。 然后从这n各院的所有排列中找出有最小长度的圆排列。如上图所示。
分析与总结:
这题是做的比较纠结的一道题, 求所有的排列很容易,但是要求圆排列的长度却令人纠结,需要考虑的情况比较多。
我的做法是建立一个坐标轴,然后把第一个圆与x轴和y轴相切,然后一个一个圆放入坐标轴中,只需要存好每个圆的圆心
在坐标的坐标即可。
求放入坐标轴后与相连的两个圆的圆心的水平距离:
h = r2-r1;
L = sqrt( (r1+r2)^2 - (r1-r2)^2 );
那么新加入圆的x坐标为上一个相接的那个圆的x坐标+L
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索touch
, of
, The
, must
that
big bang fxxk it、make it big、make it big 张靓颖、big bang fxxk it mp3、some like it big资源,以便于您获取更多的相关知识。