2.5 case packing

Source: Internet
Author: User

Problem description
The shape of products manufactured by a factory is cuboid. The height is h, and the length and width are equal. There are six products in total.
Models. Their lengths and widths are 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. these products usually use a 6*6 * H long square
Package and mail it to the customer. Because postage is very expensive, the factory should try to reduce
Number of packages. They need a good program to help them solve the problem and save money. Now this program is composed
You can design it.
Input data
The input file contains several lines, each representing an order. Each line in an order contains six integers, with null in the middle.
The number of products 1*1 to 6*6. The input file ends with a row consisting of six zeros.
Output requirements
In addition to six zeros in the last input row, each row in the input file corresponds to one row in the output file, and each row enters
An integer indicates the minimum number of packages required for the corresponding order.
Input example
0 0 4 0 0 1
7 5 1 0 0 0
0 0 0 0 0 0
Output example
2
1
Solutions
This problem is clearly described. Here we will only explain the input and output sample: There are two groups of valid input,
The first group indicates that there are four 3*3 products and one 6*6 products. At this time, four 3*3 products occupy one box.
A 6*6 product occupies 1 box, so the number of boxes is 2; the second group indicates there are 7 1*1 products, 5 2*2
And a 3*3 product, we can put them all in a box, so the output is 1.
The following figure shows how the boxes used by the six models are as follows: each product of the six models occupies a complete box.
Sub-accounts, and there is no free space; each 5*5 product occupies a new box, and 11 products can be stored in 1*1
The free space of the product; each 4*4 product occupies a new box and leaves 5 products that can hold 2*2
3*3 products are complex. First, 3*3 products cannot be stored in 5*5 or 4*4 products.
In the box, you must open another box for the 3*3 product. The number of new boxes equals to the number of 3*3 products divided
4. rounded up. At the same time, we need to discuss how much 2*2 and
1*1 product (if there is space to store 2*2 products, we will include it in 2*2 free space.
2*2 products are fully loaded. If there is still 2*2 space remaining, convert them into 1*1 space remaining ). We
We can discuss the remaining vacancies in the New Boxes opened by products 3*3 in four cases: first, 3*3
The number of products is exactly a multiple of 4, so there is no free space. Second, the number of products 3*3 is a multiple of 4 plus 1,
At this time, there are 5 2*2 vacancies and 7 1*1 vacancies. In the third case, the number of products in 3*3 is a multiple of 4 plus 2.
Three 2*2 vacancies and six 1*1 vacancies are left. In the fourth case, the number of products in 3*3 is a multiple of 4 plus 3.
One 2*2 space and five 1*1 space are left. After 3*3 products are processed, we can compare the remaining 2*2 space.
And the number of 2*2 products. If the number of products is large, all the 2*2 vacancies will be filled, and then 2*2 products will be created.
Open a new box and calculate the 1*1 space in the new box. If there are many available space, fill in 2*2 products.
And then convert the remaining 2*2 to 1*1. Finally, process the 1*1 product and compare 1*1.
The number of products with 1*1. If there are many products with 1*1 blank, fill in all the products with 1*1 blank. Otherwise, empty 1*1 first.
Fill the space, and then open a new box for 1*1 products.

Reference Program:

# Include <stdio. h> void main () {int N, A, B, C, D, E, F, Y, X; // n is used to store the number of required boxes, Y is used to store 2*2 vacancies // X is used to store 1*1 vacancies. Int U [4] = {0, 5, 3, 1}; // array U indicates that the number of products 3*3 is a multiple of 4, a multiple of 4 + 1, when the multiples of 4 are + 2 and 4 are + 3 //, the number of 2*2 vacancies remaining in the new box opened by 3*3 products while (1) {scanf ("% d", & A, & B, & C, & D, & E, & F ); if (A = 0 & B = 0 & C = 0 & D = 0 & E = 0 & F = 0) break; N = F + E + D + (C + 3)/4; // here is a tip-(C + 3) /4 is equal to the result of dividing C by 4 and rounded up, the same below y = 5 * D + U [C % 4]; If (B> Y) N + = (B-y + 8)/9; X = 36 * n-36 * F-25 * E-16 * D-9 * C-4 * B; if (A> X) N + = (a-x + 35)/36; printf ("% d \ n", n );}}

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.