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 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.
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 66. 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
这道题目的意思是有高度已经确定的不同的物品若干个,分别为11,22,33,44,55,66,六种类型,现如今手中只有6*6的同等高度的箱子,问至少需要多少个箱子才能把物品装完。
因为已经确定了高度,所以就直接把这些当成平面上的了,不然容易绕晕。
因为只有六种类型,所以可以直接进行模拟;
代码如下;
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
int main()
{
ll a,b,c,d,e,f;
ll sum,ans;
while(~scanf("%lld %lld %lld %lld %lld %lld",&a,&b,&c,&d,&e,&f))
{
sum=0;
if(a==b&&a==c&&a==d&&a==e&&a==f&&a==0) break;
sum=f;//6*6的箱子
sum+=e;//5*5的箱子
if(a>=11*e) a-=11*e;
else a=0;
sum+=d;//4*4的箱子
ans=20*d;//4*4的箱子剩余的方块数,可以装2*2和1*1的箱子。
if(ans!=0)
{
if(b*4>=ans)
{
b=((b*4)-ans)/4;
ans=0;//控制先后顺序
}
else
{
ans-=b*4;//装完2*2的箱子后剩余的方块数
b=0;//控制先后顺序
if(a>ans) a-=ans;
else a=0;
}
}
sum+=c/4;//可以装3*3的箱子4个;
if(c%4==3)
{
sum+=1;
if(b>=1)//可以装1个2*2的箱子
{
b--;
if(a>=5)//可以装5个1*1的箱子
a-=5;
else a=0;
}
else
{
if(a>=9)//可以装9个1*1的箱子
a-=9;
else a=0;
}
}
else if(c%4==2)//还剩2个3*3的箱子
{
sum+=1;
if(b>=3)//可以装3个2*2的箱子
{
b-=3;
if(a>=6)//可以装6个1*1的箱子
a-=6;
else a=0;
}
else//还剩18个方格
{
ans=18-4*b;
b=0;//控制先后顺序
if(a>ans) a-=ans;
else a=0;
}
}
else if(c%4==1)//还剩1个3*3的箱子
{
sum+=1;
if(b>=5)//可以装5个2*2的箱子
{
b-=5;
if(a>=7)//可以装7个1*1的箱子
a-=7;
else a=0;
}
else//还剩27个方格
{
ans=27-b*4;
b=0;//控制先后顺序
if(a>=ans)
a-=ans;
else a=0;
}
}
if(b!=0)
{
if(b%9==0)
{
sum+=b/9;
b=0;//控制先后顺序
}
else
{
sum+=b/9+1;
ans=b%9;
a-=(36-4*ans);
if(a<0) a=0;
}
}
if(a!=0)
{
if(a%36==0) sum+=a/36;
else sum+=a/36+1;
}
printf("%lld\n",sum);
}
return 0;
}