http://poj.org/problem?id=1017
Factory production height are h, length and width are 1x1 2x2 3x3 4x4 5x5 6x6 6 kinds of square items, to customers need packaging, packaging box length and width high for 6x6, height of H, in order to reduce costs, ask at least how many boxes to put all the items in. Each line has 6 numbers representing the number of items in the 1x1 2x2 3x3 4x4 5x5 6x6.
From big to small processing, first put 6x6 put one need a box, in put 5x5, each also need a box, but also can put 11 1x1 items, put 4x4 items, can also put 2x2 and 1x1, the most complex things put 3x3, there are a variety of circumstances need to consider, to be careful, I also use other people's test data to change out.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <vector>5#include <cstring>6#include <string>7#include <algorithm>8#include <string>9#include <Set>Ten#include <functional> One#include <numeric> A#include <sstream> -#include <stack> -#include <map> the#include <queue> - - #defineCL (arr, Val) memset (arr, Val, sizeof (arr)) - + #definell Long Long - #defineINF 0x7f7f7f7f + #defineLC L,m,rt<<1 A #defineRC M + 1,r,rt<<1|1 at #definePi ACOs (-1.0) - - #defineL (x) (x) << 1 - #defineR (x) (x) << 1 | 1 - #defineMID (L, R) (L + R) >> 1 - #defineMin (x, y) (x) < (y)? (x): (y) in #defineMax (x, y) (x) < (y)? (y): (x) - #defineE (x) (1 << (x)) to #defineIabs (x) (x) < 0? -(x): (x) + #defineOut (x) printf ("%i64d\n", X) - #defineLowbit (x) (x) & (-X) the #defineRead () freopen ("A.txt", "R", stdin) * #defineWrite () freopen ("B.txt", "w", stdout); $ #defineMAXN 1000000000Panax Notoginseng #defineN 10010 - using namespacestd; the + intMain () A { the //Read (); + //Write () - inta,b,c,d,e,f,s; $ while(~SCANF ("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)) $ { - if(a+b+c+d+e+f==0) Break; -S=f;//6*6 's the if(e>0)//5*5 's - {Wuyis+=e; thea-= One*e; - } Wu //printf ("%d%d\n", s,a); - if(d>0)//4x4 's About { $s+=D; - intb1=5*d;//You can put B1 a 2x2. -b-=B1; - if(b<0)//2x2 is not enough, just put a 1x1 A { +a-=-4*b; the } - } $ //printf ("%d%d%d\n", s,a,b); the if(c>0) the { thes+=c/4; the intc1=c%4; - if(C1) in{//discussion of the situation, c1=1,=2,=3 thes++; the if(b>0) About { the intb1=b; the if(c1==1) b-=5; the Else if(c1==2) b-=3; + Else if(c1==3) b-=1; - if(b>=0) a-= $-c1*9-(b1-b) *4;//You can also put a 1x1 the Elsea-= $-c1*9-b1*4;Bayi } the Elsea-= $-c1*9; the } - } - //printf ("%d%d%d\n", s,a,b); the if(b>0)//2x2 's the { thes+=b/9; the intb1=b%9; - if(B1) the { thes++; the if(a>0) a-= $-b1*4;94 } the } the if(a>0)//1x1 's the {98s+=a/ $; About if(a% $>0) s++; - }101printf"%d\n", s);102 }103 return 0;104}
poj-1017 Packets (greedy)