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;
    }
  • 相关阅读:
    线性DP SGU167 I-country
    背包问题 POJ1742 Coins
    背包问题 codevs2210 数字组合
    dfs+贪心 BZOJ4027 [HEOI2015] 兔子与樱花
    spfa最短路+DP BZOJ1003 [ZJOI2006] 物流运输
    矩阵乘法 POJ3070 Fibonacci
    tarjan+spfa最短路 BZOJ1179 [Apio2009] Atm
    欧拉函数 BZOJ2190 [SDOI2008] 仪仗队
    矩阵乘法 洛谷 P3390【模板】矩阵快速幂
    裴蜀定理 BZOJ2299[HAOI2011] 向量
  • 原文地址:https://www.cnblogs.com/tianmin123/p/4634985.html
Copyright © 2011-2022 走看看