Ultraviolet A 311 Packets

Source: Internet
Author: User

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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.