zoukankan      html  css  js  c++  java
  • [poj解题]1017

    Packets
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 41014   Accepted: 13776

    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>
    #include <string.h>
    
    int main(){
        int a,b,c,d,e,f;
        int al, bl;
        int total;
        int tmp;
    
        a = b = c = d = e = f = 0;
    
        while(1){
            total = 0;
            tmp = 0;
            al = bl = 0;
            scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
    
            if(a == 0&& b == 0 && c == 0&& d == 0 && e == 0 && f ==0){
                break;
            }
    
            /*
                6*6
            */
            total += f;
            /*
                5*5
            */
            if(e>0){
                total += e;
                al += 11 * e;
            }
    
            /*
                4*4
            */
            if(d>0){
                total += d;
                bl += 5 * d;
            }
    
            /*
                3*3
            */
            if(c > 0){
                tmp = (c%4 == 0)? 0:1;
                total += (c/4 + tmp);
                tmp = c%4;
                if(tmp == 1){
                    al += 7;
                    bl += 5;
                }
                else if(tmp == 2){
                    al += 6;
                    bl += 3;
                }
                else if(tmp == 3){
                    al += 5;
                    bl += 1;
                }
            }
    
            /*
                2 * 2
            */
            if(b > 0){
                if(b<=bl) {
                    al += 4 * (bl - b);
                    bl = 0;
                    b = 0;
                }
                else{
                    b -= bl;
                    bl = 0;
                }
            }
    
            if(b > 0){
                tmp = (b%9 == 0)? 0:1;
                total += (b/9 + tmp);
                if(b%9 !=0){
                    al += 36 - 4*(b %9);
                }
                b = 0;
            }
    
            al += bl * 4;
    
            if(a > 0){
                if(a<=al){
                    a = 0;
                }
                else{
                    a = a - al;
                }
            }
    
            tmp = (a%36 == 0)? 0:1;
            total += (a/36 + tmp);
            printf("%d
    ", total);
        }
    
        return 0;
    }
    

      

  • 相关阅读:
    分享上大学时CCTV5经常播放的一段宣传片
    嗯, 在Vista下面post一篇, 快过年的二三事
    [转自天涯]很多年以前,我是一个中锋
    关于Anthem的Button控件, 为啥仍然会PostBack?
    小白三下杭州
    搜狗, 谷歌, 紫光, 3大输入法互打结果.
    2008春节回家流水账
    早上拍的雪景.
    如果安装.net framework 3.5出错, 可以这样解决
    我那幸福的坐车偶记...
  • 原文地址:https://www.cnblogs.com/igloo1986/p/3509943.html
Copyright © 2011-2022 走看看