Blog·Tanky WooABOUTRSS

百练 OJ 1017 POJ1017装箱子

24 May 2010
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

//ID: 百练 OJ 1017 POJ1017装箱子 //题目地址: http://poj.grids.cn/problem/1017 //My Name: Tanky_Woo //My Website: C++奋斗乐园|C++学习|算法学习|ACM/ICPC学习 //Website Link: http://www.cpply.com/ //My BBS: C++奋斗乐园|C++论坛|算法论坛|ACM/ICPC论坛 //BBS Link:http://www.cppleyuan.com/ //My Blog:www.wutianqi.com //豆瓣小组:http://www.douban.com/group/cppleyuan/ //转载请写上本帖链接 www.cpply.com|www.cppleyuan.com|www.wutianqi.com //及名称"Tanky Woo与ACM一起走过的日子"和“C++奋斗乐园|C++论坛|算法论坛|ACM/ICPC论坛”

 #include 
using namespace std;
int a, b, c, d, e, f;
int main()
{
    int nPackets, nLeft;   //nPackets表示供需要多少箱子, nleft表示 3*3的产品在占满每个6*6的箱子后还剩几个没装
    int Three_Packets[4] = {0, 5, 3, 1};  //表示一个6*6的箱子在装满nLeft个3*3产品后剩余可以装多少2*2的产品
    while(scanf("%d%d%d%d%d%d", &a;, &b;, &c;, &d;, &e;, &f;) == 6
        && (!(a==0 && b==0 && c==0 && d==0 && e==0 && f==0)))
    {
        nPackets = 0;
        nLeft = 0;
        nPackets += d + e + f + (c+3)/4;     
        nLeft = c % 4;
        int two_board = 5 * d + Three_Packets[nLeft];    //多余的可以装2*2产品的个数
        int one_board = 0;  //多余的可以装1*1产品的个数
        if(b > two_board)
            nPackets += ((b - two_board)+8)/9;
        one_board = 36*nPackets - 36*f - 25*e - 16*d - 9 *c - 4*b;
        if(a > one_board)
            nPackets += ((a-one_board)+35)/36;
        printf("%d\n", nPackets);
    }
    return 0;
}