Description
A factory produces products packed in square packets of the same height h and of the sizes 11, 22, 33, 44, 55, 66. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 66. 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 would 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 packets of individual size from the smallest size 11 to the biggest size 6*6. 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 1
7 5 1 0 0 0
0 0 0 0 0 0
Sample Output
2
1
题目大意:
一个工厂制造的产品有六种规格,分别为1*1, 2*2, 3*3, 4*4, 5*5, 6*6
这些产品会经由一个 6*6 的长方体箱子包装后邮寄给客户。由于邮费很贵,求给定订单后最小的邮寄箱数量。
解题思路:优先考虑规格较大的产品
6*6的产品,每个产品独占一个箱子
5*5的产品,每个产品放入一个箱子,该箱子的剩余空间允许放入的最大尺寸为1*1,且最多放11个
4*4的产品,每个产品放入一个箱子,该箱子的剩余空间允许放入的最大尺寸为2*2,且最多放入5个
3*3的产品,由于一个箱子最多可放4个产品,需要分情况考虑
2*2的产品和1*1的产品主要用于填充已使用箱子的剩余空间,且剩余空间中,一个可供2*2规格产品的空间也可以放入4个1*1规格的产品。
AC代码
#include<iostream>
using namespace std;
int num[7];
int main() {
while (true) {
for (int i = 1; i < 7; i++) {
cin >> num[i];
}
if (num[1] == 0 && num[2] == 0 && num[3] == 0 && num[4] == 0 && num[5] == 0 && num[6] == 0) { break; }
int ans = num[6] + num[5] + num[4] + (num[3] + 3) / 4;
int first = 0; int second = 0;
second += num[4] * 5; first += num[5] * 11;
if (num[3] % 4 == 3) { second += 1; first += 5; }
else if (num[3] % 4 == 2) { second += 3; first += 6; }
else if (num[3] % 4 == 1) { second += 5; first += 7; }
if (num[2] > second) {
num[2] -= second; ans++;
while (num[2] > 9) { ans++; num[2] -= 9; }
first += 36 - 4 * num[2];
}
else {
first += (second - num[2]) * 4;//未被使用的2*2空间可以让1*1产品使用
}
if (num[1] > first) {
num[1] -= first;
ans += (num[1] + 35) / 36;
}
cout << ans << endl;
}
}