zoukankan      html  css  js  c++  java
  • POJ-1017-Packet(贪心1)

    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 
    #include<stdio.h>
    int cnt2[4]= {0,5,3,1};
    int main()
    {
        int d[10];
        while(scanf("%d%d%d%d%d%d",&d[1],&d[2],&d[3],&d[4],&d[5],&d[6])&&d[1]+d[2]+d[3]+d[4]+d[5]+d[6])
        {
            int n=0;
            n+=d[6]+d[5]+d[4]+(d[3]+3)/4;//一个6*6的箱子最多只能装4个3*3的箱子
            //当d[3]等于5的时候 就要拿另外一个箱子 5加上另外三个空位对4除 则需要两个了
            int d2=d[4]*5+cnt2[d[3]%4]; //d[3]对四取余范围为0到3 一一对应上面找出的规律
            if(d2<d[2])
            {
                n+=(d[2]-d2+8)/9;//当多出的大于了9 10+8/9=2 则另外还需要两个箱子
            }
            int d1=n*36-d[6]*36-d[5]*25-d[4]*16-d[3]*9-d[2]*4;
            if(d1<d[1])
            {
                n+=(d[1]-d1+35)/36;
            }
            printf("%d
    ",n);
        }
        return 0;
    }
  • 相关阅读:
    SQL 操作结果集 -并集、差集、交集、结果集排序
    MongoDB系列四:解决secondary的读操作
    org.apache.hadoop.ipc.RemoteException: User: root is not allowed to impersonate root
    hive 中窗口函数row_number,rank,dense_ran,ntile分析函数的用法
    FormData上传文件同时附带其他参数
    Hive删除分区
    Hive日期格式转换用法
    HIVE 不支持group by 别名
    ODS与EDW的区别
    hive数据类型转换、字符串函数、条件判断
  • 原文地址:https://www.cnblogs.com/tianmin123/p/4634985.html
Copyright © 2011-2022 走看看