1464 Packing Problem
DescriptionDescription
The shape of a product manufactured by a factory is cuboid. The height is h, and the length and width are equal. There are six models in total. Their lengths and widths are 1*1, 2*2, respectively, 3*3, 4*4, 5*5, 6*6. These products are usually packaged in a 6*6 * h rectangular box and then mailed to the customer. Because postage is very expensive, the factory should try to reduce the number of parcels for each order. They need a good program to help them solve the problem and save money. Now this program is designed by you.
Input description
Input Description
The input file contains several lines, each representing an order. Each line in an order contains six integers separated by spaces, which are the number of products 1*1 to 6*6, respectively. The input file ends with a row consisting of six zeros.
Output description
Output Description
In addition to six zeros in the last input row, each row in the input file corresponds to a row in the output file. Each row outputs an integer representing the minimum number of packages required for the corresponding order.
Sample Input
Sample Input
0 0 4 0 0 1
7 5 1 0 0 0
0 0 0 0 0 0
Sample output
Sample Output
2
1
Data range and prompt
Data Size & Hint
The data range is small. Just simulate it.
CATEGORY tag
Tags click here to expand
Relatively simple simulation. Pay attention to 6*6 + + 5*5 + + 4*4 + + and then process the remaining space.
1 # include <iostream> 2 # include <cstdio> 3 using namespace std; 4 int tot; 5 int main () 6 {7 int a1, a2, a3, a4, a5, a6; 8 while (scanf ("% d", & a1, & a2, & a3, & a4, & a5, & a6) 9 {10 tot = 0; 11 if (a1 = 0 & a2 = 0 & a3 = 0 & a4 = 0 & a5 = 0 & a6 = 0) 12 break; 13 for (int I = 1; I <= a6; I ++) 14 tot ++; 15 int kong5 = (36-25) * a5; 16 for (int I = 1; I <= a5; I ++) 17 tot ++; 18 while (kong5> 0 & a1> 0) 19 {20 a1 --; 21 kong5 --; 22} // when the length is 5*5, only 1 can be filled with 2 3 for (int I = 1; I = a4; I ++) 24 tot ++; 25 int kong4 = (36-16) * a4; 26 while (kong4> 0 & a2> 0) 27 {28 a2 --; 29 kong4 = kong4-4; 30} 31 while (a1> 0 & kong4> 0) 32 {33 a1 --; 34 kong4 --; 35} 36 int a3yu = a3 % 4; // The number of the remaining a3 after being filled with a3 is 37 int kong3; 38 if (a3yu! = 0) 39 {40 tot ++; 41 kong3 = (36-9 * a3yu); 42} 43 for (int I = 1; I <= a3/4; I ++) 44 tot ++; 45 while (a2> 0 & kong3> 0) 46 {47 a2 --; 48 kong3 = kong3-4; 49} 50 while (a1> 0 & kong3> 0) 51 {52 a1 --; 53 kong3 --; 54} 55 int a2yu = a2 % 6; 56 int kong2 = (36-a2yu * 4); 57 tot = tot + (a2/6); 58 while (kong2> 0 & a1> 0) 59 {60 kong2 --; 61 a1 --; 62} 63 int a1yu = a1 % 36; 64 tot = tot + a1/36; 65 if (a1yu! = 0) 66 tot ++; 67 printf ("% d \ n", tot); 68} 69 70 return 0; 71}