UVA how Big is It?

Source: Internet
Author: User

Topics such as the following:

How Big is It?
Ian's going to California, and he had to pack his things, including hiscollection of circles. Given a set of circles, your program mustfind the smallest rectangular box in which they fit. All circles must touch the bottom of the box. The figure below Showsan acceptable packing for a set of circles (although this could not be bethe optimal packing for these PA Rticular circles). Note that in anideal packing, each circle should touch at least one other circle (but you probably figured, this out).InputThe first line of input contains a single positive decimal integer N, N<=50. This indicates the number of lines which follow. Thesubsequent NLines each contain a series of numbers separated byspaces. The first number on each of the these lines is a positive integer m, m<=8, which indicates how many other numbers appear on Thatline. The next mNumbers on the line is the radii of the Circleswhich must is packed in a single box. These numbers need not beintegers.OutputFor each data line of input, excluding the first line of input containing N, your program must output the size of the smallest rectangle which canpack the circles. Each case should is output on a separate line by Itself,with three places after the decimal point. Do not output leading zeroesunless the number was less than 1, e.g. 0.543.Sample Input
33 2.0 1.0 2.04 2.0 2.0 2.0 2.03 2.0 1.0 4.0
Sample Output
9.65716.00012.657

The minimum length of the rectangle in which the given circle is to be placed. This problem has a few details that would have been infinitely WA. I was just beginning to think that the whole circle, the length of each case to calculate the minimum value, the result WA. Due to the length of each case. I am if each circle is tangent to the previous circle, it is not necessarily true. For example, there are two very large round tangent, they can have a lot of small circle, and these two circles does not necessarily tangent. So using the previous method to figure out the result is small.

On the Internet to participate in other people's code, found that they are set up an array to record the center coordinate, to find each center coordinate, is to find the circle tangent to the previous circle of the center of the coordinates of the maximum value, because the circle is now considered the most right circle, so its center coordinate is the largest, and due to the shortest rectangle length, So at least one of the previous circles is tangent (not necessarily the previous one). The leftmost coordinate is the minimum value of the center coordinate minus the radius, and the rightmost coordinate is the center coordinate plus the maximum radius size, and the minimum value of the leftmost value minus the rightmost is the minimum length of the rectangle.

The code for the AC is as follows:


UVA how Big is It?

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.