Packets

版权声明:未经博主允许,不准转发。 https://blog.csdn.net/ACMerdsb/article/details/89247540

Problem Description
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 66. 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
Hint
Source
Central Europe 1996 Central Europe 1996 Central European Regionals 1996

AC代码://最朴素的代码。
//以后绝对不会说时间都去哪里了,因为时间都让粗心大意浪费了。
//这个题就是平面题目,硬是做成了立体的。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
//这个题目的关键点是等高。就是看平面就行。
//填充的时候如果不够,就先用大的填充,再用小的进行填充。
int main()
{
    int a,b,c,d,e,f;
    while(~scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f))
    {
    	//终止条件。
        if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)
            break;
        int sum = 0;//记录所用的盒子的数目。
        
        sum += f;//6

        sum += e;//5 单个用1*1填充。(6*6+5*6+5*5=91)
        if(a>11*e)   //填充后剩余的1*1的个数。
            a -= 11*e;
        else a = 0;

        sum += d;//4 单个先用2*2填充,再用1*1填充。
        b = b-5*d;
        if(b<0)
        {
            if(a>(-b)*4)
                a -= (-b)*4;
            else a = 0;
            b = 0;
        }

        sum += c / 4;//3   就3*3的比较麻烦,其他的都很简单。
        if(c%4==3)
        {
            b -= 1;
            if(b<0)
            {
                if(a>(-b)*4)
                    a -= (-b)*4;
                else a = 0;
                b = 0;
            }
            if(a>5)
                a -= 5;
            else a = 0;
            sum++;
        }
        else if(c%4==2)
        {
            b -= 3;
            if(b<0)
            {
                if(a>(-b)*4)
                    a -= (-b)*4;
                else a = 0;
                b = 0;
            }
            if(a>6)
                a -= 6;
            else a = 0;
            sum++;
        }
        else if(c%4==1)
        {
            b -= 5;
            if(b<0)
            {
                if(a>(-b)*4)
                    a -= (-b)*4;
                else a = 0;
                b = 0;
            }
            if(a>7)
                a -= 7;
            else a = 0;
            sum++;
        }

        sum += (b / 9);//2
        if(b%9!=0)
        {
            if(a>(9-b%9)*4)
                a -= (9-b%9)*4;
            else a = 0;
            sum++;
        }

        sum += a/36;//1
        if(a%36!=0)
        {
            sum++;
            a = 0;
        }
        printf("%d\n",sum);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ACMerdsb/article/details/89247540
今日推荐