码迷,mamicode.com
首页 > 其他好文 > 详细

poj 1017 Packets

时间:2014-07-19 08:11:38      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   strong   os   width   

Packets
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 43436   Accepted: 14637

Description

A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6*6. Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary 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 according to an order would save a lot of money. You are asked to make such a program.

Input

The input file consists of several lines specifying orders. Each line specifies 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 1*1 to the biggest size 6*6. The end of the 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 into which the order 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 


分析:
装箱问题,利用贪心的思想,从最大的开始装
6×6,5×5和4×4的每个都需要一个箱子
5×5的和11个1×1的装一起,4×4的和5个2×2的装一起
3×3的分4种情况
1.正好装满
2.剩一个,则装5个2×2的,7个1×1的
3.剩两个,则装3个2×2,6个1×1的
4.剩三个,则装1个2×2的,5个1×1的
还要多余的2×2的,装完后用1×1的填充
若2×2的不够,原来用2×2的用1×1的填充


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int p[4]={0,5,3,1}; 
 //3×3的放完后,余下的放入新箱子后,还可以放几个2×2的包裹(下标对应余数)
int main ()
{
	int a,b,c,d,e,f;
	int k1,k2,sum;
	while(cin>>a>>b>>c>>d>>e>>f)
	{
		if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0) break;
		sum=f+e+d+(c+3)/4;
		// 6*6,5*5,4*4每个都要用一个箱子,3*3的对4向上取整
		k1=d*5+p[c%4];  
		// 把2*2和4*4(3*3)放在一起时,需要2*2的个数
		if(k1<b) 
			sum+=(b-k1+8)/9;  
		     // 单独把2*2放一个箱子时,需要2*2的个数
		k2=sum*36-b*4-c*9-d*16-e*25-f*36;  
		 // 需要1*1的个数
		if(k2<a)
			sum+=(a-k2+35)/36;   
		//单独把1*1放一个箱子时,需要1*1的个数
		cout<<sum<<endl;
	}
	return 0;
}


poj 1017 Packets,布布扣,bubuko.com

poj 1017 Packets

标签:des   style   color   strong   os   width   

原文地址:http://blog.csdn.net/fyxz1314/article/details/37929631

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!