首页 > 其他 > 详细

【贪心】【POJ-1017】Packets

时间:2014-02-18 11:37:12      阅读:207      评论:0      收藏:0      [点我收藏+]

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 
bubuko.com,布布扣
/*********************************************************************************************************
先附上我的渣代码.........写的太渣了....
题意:给出盒子尺寸分别为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\n", ans);
    }
    return 0;
}
bubuko.com,布布扣

【贪心】【POJ-1017】Packets

原文:http://www.cnblogs.com/ahu-shu/p/3553346.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!