UVA 311 Packets

 

贪心,用到了许多小技巧,向下取整等。

CODE:

 

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using  namespace std;

int u[ 4] = { 0531};    // 以三的剩余个数进行分类 

int main()
{
     int one, two, three, four, five, six;
     while(scanf( " %d%d%d%d%d%d ", &one, &two, &three, &four, &five, &six))
    {
         int tot =  0;
         if(one ==  0 && two ==  0 && three ==  0 && four ==  0 && five ==  0 && six ==  0break;
        tot = six + five + four + (three+ 3)/ 4;     // 向下取整,计算3x3需要的空间。 
         int y = four* 5 + u[three% 4];    // 计算可以容纳2x2箱子的个数 
         if(two > y) tot += (two-y+ 8)/ 9;            // 向下取整
         int dif =  36*tot -  36*six -  25*five -  16*four -  9*three -  4*two; // 剩余可以容纳1x1箱子的个数 
         if(one > dif) tot += (one-dif+ 35)/ 36// 向下取整 
        printf( " %d\n ", tot);
    }
     return  0;
}

 

你可能感兴趣的:(uva)