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.

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 
题目大意:

工厂生产的产品装在方形包的同一高度h和大小的1 * 1,2 * 2,3 * 3,4 * 4,5 * 5,6 * 6。广场上的这些产品总是交付给客户的包裹一样高h的产品和尺寸6 * 6。因为费用是工厂的利益以及客户的包裹需要交付的数量降到最低订购了产品从工厂到客户。一个好的程序解决问题找到所需的最小数量的包裹交付给产品根据订单会省下一大笔钱。你被要求做这样的一个程序。

 

输入

 

输入文件包含几行指定命令。每一行指定一个秩序。订单描述六个整数隔开一个空间代表先后个体大小的数据包的数量从最小的大小1 * 1的最大尺寸6 * 6。输入文件的结束由线表示包含六个零。

 

输出

 

输出文件包含一行输入文件中的每一行。这一行包含订单的最小数量的包裹从相应的输入文件可以包装。没有线相对应的输出文件的最后一个“零”行输入文件。

#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f&&(a+b+c+d+e+f))
    {
      int sum=0;
      sum=f;
      sum+=e;
      if(a!=0)
        a=max(0,a-11*e);//一个包装箱能放1个5*5的盒子和11个1*1的盒子
      sum+=d;

      if(b>=d*5)//一个包装箱只能放1个4*4盒子和5个2*2盒子

      b=b-d*5;
      else
      {
          a=max(0,a-4*(d*5-b));//2*2盒子不够的空间用1*1的盒子补
          b=0;
      }
      sum+=(c+3)/4;//小技巧  相当于向上取整
      c%=4;
      if(c)
  {
      if(b>=7-2*c)//c盒子为:1,2,3,则b盒子为5,3,1得7-2*c关系式
        {
            b-=7-2*c;
            a=max(0,a-(8-c));//尽可能多的放置2*2盒子   放完后放1*1盒子{c:1,2,3;   b:5,3,1    a:7,6,5(填充的箱子需求数)}
     } else
      {
          a=max(0,a-(36-4*b-9*c));
          b=0;
      }

  }
  sum+=(b+8)/9;
  b%=9;
  if(b)
  {
  a=max(0,a-(36-b*4));
  b=0;

  }
sum+=(a+35)/36;
cout<<sum<<endl;


    }



    return 0;
}
相关文章
|
6月前
|
人工智能 BI
UVA live 2678 - Subsequence
关于这个题目,有多种的解法,如果枚举起点和终点,时间复杂度为O(n^3),但如果我们用一个数组B把一段数的和存起来,B[i] = sum(a[1].....a[i])。这样就可以把时间复杂度降到O(n^2)。
29 0
|
7月前
|
算法
POJ3061 Subsequence
POJ3061 Subsequence
[POJ 1236] Network of Schools | Tarjan缩点
Description A number of schools are connected to a computer network. Agreements have been developed among those schools: each school maintains a list of schools to which it distributes software (the “receiving schools”).
113 0
[POJ 1236] Network of Schools | Tarjan缩点
POJ - 1032: Parliament
POJ - 1032: Parliament
85 0
|
机器学习/深度学习
POJ 1017 Packets
Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53812   Accepted: 18299 Description A factory produces prod...
959 0
|
算法 数据建模
【POJ 1236 Network of Schools】强联通分量问题 Tarjan算法,缩点
题目链接:http://poj.org/problem?id=1236 题意:给定一个表示n所学校网络连通关系的有向图。现要通过网络分发软件,规则是:若顶点u,v存在通路,发给u,则v可以通过网络从u接收到。
1147 0