POJ 1017 Packets

POj 1017 Packets

 

Packets

Time Limit: 1000MS

 

Memory Limit: 10000K

Total Submissions: 31043

 

Accepted: 10279

Description

A factory produces products packed in square packets of the sameheight h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. Theseproducts are always delivered to customers in the square parcels ofthe same height h as the products have and of the size 6*6. Becauseof the expenses it is the interest of the factory as well as of thecustomer to minimize the number of parcels necessary to deliver theordered products from the factory to the customer. A good programsolving the problem of finding the minimal number of parcelsnecessary to deliver the given products according to an order wouldsave a lot of money. You are asked to make such aprogram.

Input

The input file consists of several lines specifying orders. Eachline specifies one order. Orders are described by six integersseparated by one space representing successively the number ofpackets of individual size from the smallest size 1*1 to thebiggest size 6*6. The end of the input file is indicated by theline 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 into which theorder from the corresponding line of the input file can be packed.There is no line 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

Source

Central Europe1996

这次比赛只做出了三道题,本来应该可以再A一道,最后的一道题怎么也不懂哪里错了,样例过了,提交不是WRONGANSWER就是编译错误,

最后结束,问了一下队友,恍然大悟,

6 5 4这3个数出现一定要开一个新的,所以n=6的+5的+4的+3的/4,

然后添加2*2,每个4的可以添加5个2,3的可以添加3的%4(即05 3 1个)

不够的每个6*6都可以加9个2*2,然后把剩下的补成1*1的就行,不够的用6*6补上

#include <stdio.h> 
void main() 
{ 
 int N, a, b, c, d, e, f, y, x;//N用来存储需要的箱子数目,y用来存储 2*2 的空位数目 
                         // x 用来存储 1*1 的空位数目。 
 int u[4]={0, 5, 3, 1};      
//数组u 表示3*3 的产品数目分别是 4的倍数,4 的倍数+1, 4 的倍数+2, 4 的倍数+3 
//时,为3*3的产品打开的新箱子中剩余的 2*2的空位的个数 
 
 while(1){ 
  scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f); 
  if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0) break; 
  N = f + e + d + (c + 3) / 4;   
//这里有一个小技巧 - (c+3)/4  正好等于 c 除以4向上取整的结果,下同  
  y = 5 * d + u[c % 4];//每一个4*4的箱子装过后还可以再装5个2*2的箱子
  //还有3*3的箱子如果没填满6*6的箱子的话,也可以用来装2*2的箱子
  //5*5的箱子则只能装1*1的情况了
   if(b > y) N += (b - y + 8 ) / 9;//如果要装的2*2的箱子的数目比提供的空间要多,
   //那么多的部分要新开一些箱子 
  x = 36 * N - 36 * f - 25 * e - 16 * d - 9 * c - 4 * b; 
  if(a > x) N += ( a - x + 35 ) / 36; 
  printf("%d/n", N); 
 } 
} 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值