问题描述:A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6*6. 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.
#include <iostream>
#include<string.h>
using namespace std;
int box[7];
int sum[4] = {0,5,3,1};//对应3*3剩余空间可以放的2*2箱子
bool input()
{
int flag = 0;
memset(box,0,sizeof(box));
for(int i = 1;i < 7;i++)
{
cin >> box[i];
flag += box[i];
}
return flag;
}
int main()
{
int ans = 0;
int num = 0;
num = input();
while(num)
{
ans = box[6] + box[5] + box[4] + (box[3]+3)/4;//算出3*3,4*4,5*5,6*6所需要的箱子的个数考虑到3*3的箱子的个数可能为0,故+3
int b2 = box[4] * 5 + sum[box[3]%4];//求剩余空间可以装多少2*2的箱子
if(box[2] > b2)
{
ans+=(box[2]-b2+8)/9;
}
int b1=ans*36-box[6]*36-box[5]*25-box[4]*16-box[3]*9-box[2]*4;
if(box[1]>b1)
ans+=(box[1]-b1+35)/36;
cout << ans << endl;
num = input();
}
return 0;
}