zoukankan      html  css  js  c++  java
  • poj 1017 Packets

    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;
    }


  • 相关阅读:
    读《构建之法》第一,二,十六章的奇思妙想
    四则运算
    鉴权
    sql注入
    【信息安全作业5】散列函数的应用及其安全性
    结对作业 -GUI四则运算
    阅读《构建之法》四章、十七章
    2016012064+小学四则运算练习软件项目报告
    简单四则运算一
    梦想开花的地方
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5280491.html
Copyright © 2011-2022 走看看