poj1017(贪心)

18 篇文章 0 订阅
Packets
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 50111 Accepted: 16941

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

//题目大意:有六种高都为h底面积分别为1*1,2*2,3*3,4*4,5*5,6*6的方块.现有一种高也为h底面积
//为6*6的包装盒,现在给你这六种方块的数量,问把这些方块都装进包装盒最少需要多少个包装盒?
//解题思路:贪心题,假设1~6的方块的数量为:p1,p2,p3,p4,p5,p6;对于p6,有多少就需要多少个盒子. 
//对于5*5的方块,首先需要p5个盒子,每个盒子剩余的容量尽量放1*1的方块.然后是4*4的方块,首先需要p4
//个盒子,每个盒子剩余的容量先放2*2的盒子,在放1*1的盒子,依次类推直到将所有方块都放入盒子为止. 
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int p1,p2,p3,p4,p5,p6,n,s;
	while(scanf("%d%d%d%d%d%d",&p1,&p2,&p3,&p4,&p5,&p6)&&(p1|p2|p3|p4|p5|p6))
	{
	   n=0;
	   n+=(p5+p6);
	   if(p5>0)
	   {
	      p1=max(0,p1-11*p5);	
	   }	
	   if(p4>0)
	   {
	   	  n+=p4;
	   	  s=max(0,p4*20-p2*4);
	   	  if(s)
	   	  {
	   	     p2=0;
			 p1=max(0,p1-s);	
		  }
		  else
		  {
		  	p2=p2-p4*5;
		  }
	   }
	   if(p3>0)
	   {
	   	 n+=(p3+3)/4;
	   	 p3=p3%4;
	   	 if(p3==1)
	   	 {
	   	    p2=max(0,p2-5);
	   	    p1=max(0,p1-7);
		 }
		 else if(p3==2)
		 {
		 	p2=max(0,p2-3);
		 	p1=max(0,p1-6);
		 }
		 else  if(p3==3)
		 {
		 	p2=max(0,p2-1);
		 	p1=max(0,p1-5);
		 }
	   }
	   if(p2>0)
	   {
	   	 n+=(p2+8)/9;
	   	 p2=p2%9;
	   	 s=36-p2*4;
	   	 p1=max(0,p1-s);
	   }
	   if(p1>0)
	   {
	   	 n+=(p1+35)/36;
	   }
	   printf("%d\n",n);
	}	
} 



                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bokzmm

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值