Ultraviolet A 311-packets

Source: Internet
Author: User

Link:

Http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & category = 113 & page = show_problem & problem = 247

Original question:

A factory produces products packed in square packets of the same heightHAnd of the sizes ,,,,,.
These products are always delivered to mers MERs in the square parcels of the same heightHAs the products have and of the size.
Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number
Of parcels necessary to deliver the given products according to an order wocould save a lot of money. You are asked to make such a program.

Input

The input file consists of several lines specifying orders. Each line specifies one order. Orders are described by six integers separated by one space representing successively the number of packages
Individual size from the smallest size to the biggest size.
The end of the input file is indicated by the line containing six zeros.

Output

The output file contains one line for each line in the input file. This line contains the minimal number of parcels into which the order from the corresponding line of the input file can be packed. There
Is no line in the output file corresponding to the last ''null'' line of the input file.

Sample Input

0 0 4 0 0 17 5 1 0 0 00 0 0 0 0 0

Sample output

21

Question:

Boxes of 1*5, 6*6 sizes must be packed in 6*6 boxes with the same height. Use the minimum 6*6 boxes to pack all sizes of the boxes.

Analysis and Summary:

In volume
4. The last question in the algorithm design topic is mainly because there is no idea. It is best to refer to others' ideas.


6*6 boxes can be filled with boxes of various sizes. The following situations may occur:

1x6

1x5 + 11x1X1

1 4*4 + 5 2*2 (2*2 is preferred when there is a gap. If 2*2 is not completed, 1*1 is left for the rest)

When 3*3 is placed, the combination is complex. When 3*3 is not completed, the remaining gaps are prioritized as many as possible to put 2*2
When you place 1 3*3, you can also place 7 1*1 and 5 2*2
When you place 2 3*3, you can also place 6 1*1 and 3 2*2
When you place 3 3 3*3, you can also place 5 1*1 and 1 2*2

Because a 4*4, 5*5, 6*6 can only be placed in a box, how many boxes are needed for installation.

Then, because 3*3 can be combined with 1*1 and 2*2, you can determine the boxes required for 3*3.


In the calculation, we can first determine the number of boxes after 3*3, 4*4, 5*5, and 6*6. Assume It is a T box.

Then there will be gaps in the T box, and the 2*2 will be placed in the gaps in the T box first. If these gaps cannot be filled with 2*2, you need to add the box to know how to finish it. Finally, consider placing 1*1.

Code:

/** Ultraviolet A: 311-packets * Time: 0.008 S * Author: d_doubel **/# include <iostream> # include <cstdio> using namespace STD; int arr [7]; // set the combination of 3 in 6*6 to give priority to 2*2. // when one 3*3 is placed, you can also place 7 1*1 and 5 2*2 // when you place 2 3*3, you can also place 6 1*1 and 3 2*2 // when you place 3 3*3, you can also place 5 1*1 and 1 2 * 2int three [4] [2] = {0, 0}, {7, 5}, {6, 3}, {5 }}; int main () {While (~ Scanf ("% d", & arr [1], & arr [2], & arr [3], & arr [4], & arr [5], & arr [6]) {If (! Arr [1] &! Arr [2] &! Arr [3] &! Arr [4] &! Arr [5] &! Arr [6]) break; int ans = (ARR [3] + 3)/4 + arr [4] + arr [5] + arr [6]; // 3*3, 4*4, 5*5, 6*6 use several arr [1]-= arr [5] * 11 together; // a 5*5 and 11 1*1 can be placed for 6*6, therefore, put 1*1 and 5*5 in a box with priority int left_for_2 = three [arr [3] % 4] [1] + arr [4] * 5; // how many 2*2 if (ARR [2] <= left_for_2) can be placed in the gaps in the used box) {// arr [1]-= three [arr [3] % 4] [0] when the space in the used box can be placed in 2*2 boxes; // The number of 1*1 pairs that can be combined with 2*2 in the gap. Arr [2]-= left_for_2; arr [1] + = arr [2] * 4; // If 2*2 is a negative number, it indicates that the absolute value of the negative number is a gap and can be used to place 1*1 if (ARR [1]> 0) // if 1*1 still exists, add box ans + = (ARR [1] + 35)/36 ;} else {// 2*2 arr [1]-= three [arr [3] % 4] [0] cannot be placed; // The previous and 2*2 combinations fill the box with 1*1 arr [2]-= left_for_2; ans + = (ARR [2] + 8)/9; // Add a box until 2*2 arr [1]-= (9-arr [2] % 9) * 4 can be filled with 2*2, you can also place 1*1 If (ARR [1]> 0) ans + = (ARR [1] + 35)/36;} printf ("% d \ n ", ans);} return 0 ;}

-- The meaning of life is to give it meaning.

Original Http://blog.csdn.net/shuangde800 , By d_double (reprinted, please mark)

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.