zoukankan      html  css  js  c++  java
  • 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
    ", ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    ASP.NET缓存:缓存ASP.NET页
    oracle小技巧:字符串原样输出
    ASP.NET缓存:概述
    如何设计表结构便于treeview显示?
    Delphi VCLSkin 界面美化
    txt文件导入存储过程
    TreeView挺入数据库
    TreeView使用笔记
    TreeView格式
    TreeView学习总结
  • 原文地址:https://www.cnblogs.com/Apro/p/4496657.html
Copyright © 2011-2022 走看看