UVa 10012:how is It? Circle arrangement Problem

Source: Internet
Author: User
Tags pack

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.