Poj 1017 Packets【贪心】

A factory produces products packed in square packets of the same height h and of the sizes 11, 22, 33, 44, 55, 66. 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 11 to the biggest size 66. 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的方形包装,尺寸为11、22、33、44、55、66。这些产品始终以与产品高度h相同且尺寸为6*6的方形包裹交付给客户。由于费用的原因,尽量减少从工厂向客户交付订购产品所需的包裹数量是工厂和客户的利益所在。一个好的程序解决了根据订单交付给定产品所需的最小数量包裹的问题,将节省大量资金。你被要求制作这样一个节目。

输入

输入文件由指定顺序的几行组成。每行指定一个订单。顺序由六个整数描述,由一个空格分隔,依次表示从最小大小11到最大大小66的各个大小的数据包的数量。输入文件的结尾由包含六个零的行表示。

输出

输出文件为输入文件中的每一行包含一行。此行包含可将输入文件对应行中的订单打包到其中的最小数量的包裹。

代码

//注意题这是二位空间,不是三维空间
#include "stdio.h"
#include "algorithm"
#include "string.h"
#include "math.h"
using namespace std;
int a[9],dp[120009];
int b[6]={
    
    0,5,3,1};//3*3的个数对4取余中,
//4个3*3刚好装满6*6,即b[0]=0,3个3*3中可以装一个2*2,即b[3]=1 …… 
int main()
{
    
    
	int i,n,m=0,j;
	while(~scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6]))
	{
    
    
		n=0;
		if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0)
			break;
		int s=0;
		s=a[6]+a[5]+a[4]+ceil(a[3]/4.0);//ceil属于math.h,向上取整
		int s2=a[4]*5+b[a[3]%4];//我们现在用的s个6*6的纸中可以装多少了2*2 
		s2=min(a[2],s2);
		a[2]-=s2;//a[2]=0,代表2*2的我们装完了,否者没装完
		int s1=s*6*6-a[6]*6*6-a[5]*5*5-a[4]*4*4-a[3]*3*3-s2*2*2;
		s1=min(a[1],s1);
		a[1]-=s1;
		int k=a[2]*2*2+a[1]*1*1;
		k=ceil(k/36.0);//算剩下的2*2和1*1用到几个6*6
		s+=k;
		printf("%d\n",s); 
	}
} 

猜你喜欢

转载自blog.csdn.net/weixin_53623850/article/details/120618739