311-packets
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_ problem&problem=247
A Factory produces products packed in square packets of the same height H and of the sizes,,,,,. These products are are always delivered to customers in the square parcels of the the same heighth as the products have and the Size. Because of the expenses it is the interest of the factory as as "the" the customer to minimize the number of parcels NEC Essary to deliver the ordered products from the factory to the customer. A Good program Solving the problem of finding the minimal number of parcels necessary to deliver the given products accord ing to an order would save a lot. You are are asked to make such a.
Input
The input file consists of several lines specifying orders. Each line specifies the one order. Orders are described by six integers separated by one space representing successively the number of packets of individual Size from the smallest size to the biggest size. The "End of" input file is indicated by the line containing six zeros.
Output
The output file contains one line for each line in the input file. This line contains the minimal number of parcels to which the order from the corresponding line of the input file can Packed. There is no. in the output file corresponding to the "last ' null" line of the input file.
Sample Input
0 0 4 0 0 1 7 5 1 0 0 0 0 0 0 0 0-
0
Sample Output
2
1
Simple greed, using the method of deviation correction AC.
Complete code:
/*0.016s*/
#include <cstdio>
int main ()
{
int A, B, C, D, E, F, ans;
while (scanf ("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f), a | | b | | c | | d | | e | | f)
{
ans = F + E + D + C/4 + (c% 4 = 0? 0:1);///at least so many.
A-E, B-= 5 * d;///Although minus, even if <0 does not matter
switch (c% 4)
{case
3:a-= 5, B-= 1; break;
Case 2:A-= 6, B-= 3; break;
Case 1:A-= 7, B-= 5; break;
if (b < 0)///deviation correction
{
A + + b * 4;
b = 0;
}
Ans + = B/9 + (b% 9 = 0 0:1);///Addendum
if (b% 9) A-= (b% 9 * 4);
if (a > 0) ans + = a/36 + (a% 36 = 0? 0:1);///Addendum
printf ("%d\n", ans);
}
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/