POJ 1017 Packets

来源:互联网 发布:淘宝与天猫的关系 编辑:程序博客网 时间:2024/06/03 13:32
Packets
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 46895 Accepted: 15868

Description
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.

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 1*1 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-6的6种面积,填充一个6*6的范围,问最少能用多少个6*6个面积将这些给定的面积填充完。

边长为4,5,6的面积各占一个6*6的,4个边长为3的构成一个6*6的,边长为1,2的作为填充3,4,5,6剩下的面积的,开始的时候wa是在填充边长为2 的时候犯了错误,当作是1*2的面积开始填充,应该是个正方形,改了之后AC


#include <iostream>#include <cstdio>using namespace std;int main(void){   // freopen("C.txt","r",stdin);    int a1,a2,a3,a4,a5,a6;    while(scanf("%d%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5,&a6)!=EOF)    {        if(a1==0&&a2==0&&a3==0&&a4==0&&a5==0&&a6==0)  break;        int sum=0;        sum+=a6;        sum+=a5;  a1-=(11*a5);        sum+=a4;  a2-=(a4*5);        sum+=(a3/4); a3%=4;        switch(a3)        {            case 1: sum++;a2-=5;a1-=7;break;            case 2: sum++;a2-=3;a1-=6; break;            case 3:  sum++;a2-=1; a1-=5;        }        if(a2>=0)        {            sum+=(a2/9);            a2%=9;            if(a2) {sum++;a1-=(36-4*a2);}            if(a1>0)            {                sum+=a1/36;a1%=36;                if(a1)                    sum++;            }        }        else        {            a1+=(4*a2);            if(a1>0)            {                sum+=(a1/36);                a1%=36;                if(a1)                    sum++;            }        }        printf("%d\n",sum);    }    return 0;}


0 0
原创粉丝点击