POJ 1017 Packets

题意:有一些1×1, 2×2, 3×3, 4×4, 5×5, 6×6的货物,每个货物高度为h,把货物打包,每个包裹里可以装6×6×h,问最少几个包裹。

 

解法:6×6的直接放进去,5×5的空隙可以用1×1的填充,4×4的可以用2×2的和1×1的填充,3×3的四个可以组成一个包裹,多出来的和2×2的和1×1的组合,2×2的9个组成一个包裹,多的和1×1组合,1×1的36个组成一个包裹,按以上顺序模拟一下OTZ也不知道怎么想的……写出好多bug来

 

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
int main()
{
    int a, b, c, d, e, f;
    while(~scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) && !(a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0))
    {
        int ans = 0;
        ans += f;
        ans += e;
        int tmp = 11 * e;
        a = max(0, a - tmp);
        ans += d;
        tmp = 5 * d;
        if(b < tmp)
        {
            tmp -= b;//因为这两句写反了找了半天bug……智商拙计
            b = 0;
        }
        else
        {
            b -= tmp;
            tmp = 0;
        }
        a = max(0, a - tmp * 4);
        ans += c / 4;
        c %= 4;
        tmp = 0;
        if(c)
        {
            ans++;
            tmp = 36 - c * 9;
            int ttmp = 0;
            if(c == 1)
                ttmp = 5;
            else if(c == 2)
                ttmp = 3;
            else
                ttmp = 1;
            tmp -= ttmp * 4;
            if(b < ttmp)
            {
                ttmp -= b;
                b = 0;
            }
            else
            {
                b -= ttmp;
                ttmp = 0;
            }
            a = max(0, a - ttmp * 4 - tmp);
        }
        ans += b / 9;
        b %= 9;
        if(b)
        {
            ans++;
            a = max(0, a - 36 + 4 * b);
        }
        ans += a / 36;
        a %= 36;
        if(a)
            ans++;
        printf("%d\n", ans);
    }
    return 0;
}

  

posted @ 2015-05-12 10:38  露儿大人  阅读(164)  评论(0编辑  收藏  举报