zoukankan      html  css  js  c++  java
  • 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 
    题目大意:

    工厂生产的产品装在方形包的同一高度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;
    }
  • 相关阅读:
    jQuery(Ajax)
    博文相关接口
    登录接口设计和实现
    CSS-层叠样式表
    Google Kaptcha 生成图形验证码
    IDEA中如何修改生成javadoc里默认的author
    maven项目resources文件在target找不到
    IDEA 获取 resources 下的文件
    免安装版 mysql5.7.zip 的配置记录
    从前端模块化 到 webpack 再到使用 vue文件
  • 原文地址:https://www.cnblogs.com/jin-nuo/p/5284746.html
Copyright © 2011-2022 走看看