POJ 1017 Packets

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 

Source

 
    题目大致意思:就是有几种东西需要包装,分别是1*1 2*2 3*3 4*4 5*5 6*6的尺寸,至于高度不用考虑,因为保证高度和物品的高度是一样的。现在用6*6的包装装上述的东西,问最少需要几个包装。
    分析:
    1.6*6的单独占一个包装而且还没有剩余空间
    2.5*5的单独占一个包装,有11个1*1的剩余空间
    3.4*4的单独占一个包装,有20个1*1的剩余空间或5个2*2的剩余空间
    4.3*3的比较特殊,因为四个3*3的刚好占满一个包装,所以3*3的占的包装应该是(pack3+4)/4
    5.剩下的1*1 2*2的先从上面的剩余空间里面去补,不够在增加6*6的包装就好
 
    很简单的一道题,主要是能够分析清楚不同大小的包装占空间的关系就很容易得出答案
 
代码如下:
#include <iostream>

using namespace std;

int pack1, pack2, pack3, pack4, pack5, pack6;
int packet3[] = { 0,5,3,1 };                                     //3*3剩余2*2空间的数量

int main()
{
    int bag;
    int box1, box2;
    while (cin >> pack1 >> pack2 >> pack3 >> pack4 >> pack5 >> pack6 && (pack1 + pack2 + pack3 + pack4 + pack5 + pack6))
    {
        bag = pack6 + pack5 + pack4 + (pack3 + 3) / 4;
        box2 = pack4 * 5 + packet3[pack3 % 4];
        if (pack2 > box2) bag += (pack2 - box2 + 8) / 9;
        box1 = bag * 36 - pack2 * 4 - pack3 * 9 - pack4 * 16 - pack5 * 25 - pack6 * 36;
        if (pack1 > box1) bag += (pack1 - box1 + 35) / 36;
        cout << bag << endl;
    }
}

 

转载于:https://www.cnblogs.com/LHJL8023/p/8004109.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值