UVA_311
This topic can directly simulate the packing process, and must first be large.
① Every 6x6 occupies a box.
② Each 5*5 is placed in a box, and 11 1*1 items can be installed in it.
③ Each 4*4 is placed in a box, and five 2*2 products can be installed in it. If 2*2 is not enough, 1*1 can be placed.
④ Put every 4 3*3 in a box. If there are 3*3 remaining, we should discuss the remaining number separately.
⑤ If there are still 2*2 and 1*1 remaining, then install these.
At the same time, when both 2*2 and 1*1 can be installed, we should first install 2*2. Here is another tips: we can assume that 2*2 is sufficient. In case 2*2 becomes a negative number, we can use 1*1 to complete it, in this way, you do not need to consider whether 2*2 is not enough. For example, when 4*4 is installed, we can assume that 5 2*2 files can be installed, finally, based on the positive and negative values of 2*2, determine the remaining number of 2*2 or 1*1. Similarly, when installing 5*5, you can assume that each of the 11 products can be installed with 1*1, and the installation of 3*3 is similar.
#include<stdio.h>
#include<string.h>
int a[10];
int main()
{
int i,j,k,n;
while(1)
{
for(i=1;i<=6;i++)
scanf("%d",&a[i]);
if(!a[1]&&!a[2]&&!a[3]&&!a[4]&&!a[5]&&!a[6])
break;
n=0;
n+=a[6];
n+=a[5];
a[1]-=11*a[5];
n+=a[4];
a[2]-=5*a[4];
n+=a[3]/4;
if(a[3]%4==1)
{
a[2]-=5;
a[1]-=7;
n++;
}
else if(a[3]%4==2)
{
a[2]-=3;
a[1]-=6;
n++;
}
else if(a[3]%4==3)
{
a[2]-=1;
a[1]-=5;
n++;
}
if(a[2]<0)
{
a[1]+=4*a[2];
a[2]=0;
}
if(a[1]<0)
a[1]=0;
n+=(a[1]+4*a[2])/36;
if((a[1]+4*a[2])%36!=0)
n++;
printf("%d\n",n);
}
return 0;
}