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 
    /*********************************************************************************************************
    先附上我的渣代码.........写的太渣了....
    题意:给出盒子尺寸分别为1*1 2*2 3*3 4*4 5*5 6*6的数量,要放进6*6的大箱子中,问最少需要几个箱子
    思路:先放大的,再放小的
    6*6:每个都需要一个箱子
    5*5:每个都需要一个箱子,并且可以多放11个1*1的盒子
    4*4:每个都需要一个箱子,并且可以多放5个2*2的盒子
    3*3:每4个需要一个箱子
    并且
    (1)、如果剩1个3*3,还可以装5个2*2和7个1*1
    (2)、如果剩2个3*3,还可以装3个2*2和6和1*1
    (3)、如果剩3个3*3,还可以装1个2*2和5个1*1
    2*2和1*1用来拼前几个的空隙
    注意:
    细心点就不会错
    附几个测试数据:
    data.in
    0 0 4 0 0 1
    7 5 1 0 0 0
    36 9 4 1 1 1
    0 9 4 1 1 0
    0 0 4 0 0 0
    36 0 0 0 0 0
    0 9 0 0 0 0
    79 96 94 30 18 14
    53 17 12 98 76 54
    83 44 47 42 80 3
    15 26 13 29 42 40
    41 61 36 90 54 66
    78 56 445 45 23 65
    13 4 8 29 45 3
    15 75 45 98 34 53
    40 9 0 2 0 0
    41 9 0 2 0 0
    44 0 0 0 4 0
    0 2 3 0 0 0
    37 7 2 0 1 0
    12 2 0 1 0 0
    13 2 0 1 0 0
    0 0 0 0 0 0
     
    data.out
    2
    1
    6
    4
    1
    1
    1
    86
    231
    137
    115
    219
    245
    79
    197
    3
    4
    4
    2
    3
    1
    2
    
    *********************************************************************************************************/
    #include <cstdio>
    #include <cmath>
    int main()
    {
        //freopen("data.in" , "r" , stdin);
        //freopen("data.out" , "w" , stdout);
        int s1 , s2 , s3 , s4 , s5 , s6;
        while(scanf("%d %d %d %d %d %d", &s1 , &s2 , &s3 , &s4 , &s5 , &s6) && s1 + s2 + s3 + s4 + s5 + s6)
        {
            int ans = 0;
            ans += s6;
            ans += s5;
            int left5 = s5 * 11;
            if(s1 <= left5)
                s1 = 0;
            else
                s1 -= left5;
            ans += s4;
            int left4 = s4 * 5;
            if(s2 <= left4)
            {
                left4 -= s2;
                s2 = 0;
                left4 *= 4;
                if(s1 <= left4)
                    s1 = 0;
                else
                    s1 -= left4;
            }
            else
                s2 -= left4;
            ans += s3 / 4;
            int left3 = s3 % 4;
            if(left3)
                ans++;
            if(left3 == 1)
            {
                int left31 = 7;
                int left32 = 5;
                if(s2 <= left32)
                {
                    s2 = 0;
                    left32 -= s2;
                    left32 *= 4;
                    left31 += left32;
                }
                else
                    s2 -= left32;
                if(s1 <= left31)
                    s1 = 0;
                else
                    s1 -= left31;
            }
            if(left3 == 2)
            {
                int left31 = 6;
                int left32 = 3;
                if(s2 <= left32)
                {
                    left32 -= s2;
                    left32 *= 4;
                    left31 += left32;
                    s2 = 0;
                }
                else
                    s2 -= left32;
                if(s1 <= left31)
                    s1 = 0;
                else
                    s1 -= left31;
            }
            if(left3 == 3)
            {
                int left31 = 5;
                int left32 = 1;
                if(s2 <= left32)
                {
                    left32 -= s2;
                    left32 *= 4;
                    left31 += left32;
                    s2 = 0;
                }
                else
                    s2 -= left32;
                if(s1 <= left31)
                    s1 = 0;
                else
                    s1 -= left31;
            }
            if(s2)
            {
                ans += s2 /9;
                s2 %= 9;
                s2 *= 4;
            }
            if(s1)
            {
                ans += s1 / 36;
                s1 %= 36;
            }
            if(s1 || s2)
            {
                if(s1 + s2 <= 36)
                    ans++;
                else
                    ans += (int)ceil((s1 + s2) * 1.0/ 36);
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    /************************************************************************************************************
    超精简版...Orz中  话说这代码刚拿到我还没看懂 问了学长后才知道是怎么回事...
    首先算出来最少需要多少箱子 因为4、5、6都是直接占一个箱子 每4个3占一个 所以s6 + s5 + s4 + (s3 + 3) / 4
    然后算出来这些箱子空余多少2*2的位置可以放 接着把2*2的放进去
    然后算出来1*1的空余位置 ans*36是总的格子数 减去6、5、4、3、2所占的箱子数就是剩下的1*1的位置了
    太神了 继续Orz.......
    ************************************************************************************************************/
    #include <cstdio>
    int main()
    {
        int s1, s2, s3, s4, s5, s6;
        int mark[4] = {0 , 5 , 3 , 1};
        while(scanf("%d %d %d %d %d %d", &s1, &s2, &s3, &s4, &s5, &s6) && s1 + s2 + s3 + s4 + s5 + s6)
        {
            int ans = s6 + s5 + s4 + (s3 + 3) / 4;
            int l2 = s4 * 5 + mark[s3 % 4];
            if(s2 > l2)
                ans += (s2 - l2 + 8) / 9;
            int l1 = ans * 36 - s6 * 36 - s5 * 25 - s4 * 16 - s3 * 9 - s2 * 4;
            if(s1 > l1)
                ans += (s1 - l1 + 35) / 36;
            printf("%d
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    01开卡主流程
    eclipse开发工程右键菜单例子
    eclipse插件开发需要什么
    installshield安装程序自注册dll
    eclipse开发视图
    vbscript和cmd命令 如何获取当前文件的路径
    eclipse开发视图
    vbscript和cmd命令 如何获取当前文件的路径
    vbscript设置环境变量
    eclipse开发工程右键菜单例子
  • 原文地址:https://www.cnblogs.com/ahu-shu/p/3553346.html
Copyright © 2011-2022 走看看