首页 > 代码库 > UVA Packets (模拟)

UVA Packets (模拟)

Description

技术分享


 Packets 

A factory produces products packed in square packets of the same height h and of the sizes 技术分享 , 技术分享 , 技术分享 , 技术分享 , 技术分享 , 技术分享 . These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 技术分享 . 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 技术分享 to the biggest size 技术分享 . 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
     题意:输入6个数,分别代表底面积为1*1 2*2 3*3 4*4 5*5 6*6 的正方体箱子,求这些方块如果放在底面积为6*6的正方体箱子中需要几个。输出个数。
     代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    int a,b,c,d,e,f;
    while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)!=EOF)
    {
        if(a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0)
        {
            break;
        }
        int sum = 0;
        int aa = 0;
        int bb = 0;
        int cc = 0;
        int cnt;
        aa = 11 * e;
        bb = 5 * d;
        sum = e + d + f;
        cc = 4 - (c % 4);
        if(cc == 4)
        {
            sum = sum + (c/4);
        }
        else
        {
            sum = sum + (c/4) + 1;
        }
        if(cc == 1)
        {
            aa = aa + 5;
            bb = bb + 1;
        }
        else if(cc == 2)
        {
            bb = bb + 3;
            aa = aa + 6;
        }
        else if(cc == 3)
        {
            bb = bb + 5;
            aa = aa + 7;
        }
        if(bb >= b)
        {
            aa = aa + (bb - b)*4;
        }
        else
        {
            cnt = (b - bb)%9;
            if(cnt == 0)
            {
                sum = sum + ((b-bb)/9);
            }
            else
            {
                sum = sum + ((b-bb)/9) + 1;
                aa = aa + (9 - cnt) * 4;
            }

        }
        if(aa >= a)
        {
            printf("%d\n",sum);
        }
        else
        {
            cnt = a - aa;
            if(cnt == 0 || cnt%36 == 0)
            {
                sum = sum + (cnt/36);
            }
            else
            {
                sum = sum + (cnt/36)+1;
            }
            printf("%d\n",sum);
        }
    }
    return 0;
}

UVA Packets (模拟)