zoukankan      html  css  js  c++  java
  • POJ 1017:Packets

    Packets
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 47513   Accepted: 16099

    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*h,物品有1*1*h的,2*2*h的,3*3*h的,4*4*h的,5*5*h的,6*6*h的,给你每一种的数量,然后问需要多少个箱子。

    高度都是h,所以就是平面的,然后从大到小一直贪下去。

    代码:

    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <vector>
    #include <string>
    #include <cstring>
    #pragma warning(disable:4996)
    using namespace std;
    
    int a[8];
    
    int main()
    {
    	int sum;
    	while(cin>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6])
    	{
    		if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0)
    			break;
    		sum=0;
    
    		sum+=a[6];
    
    		sum+=a[5];
    		a[1]=max(0,a[1]-11*a[5]);
    
    		sum+=a[4];
    		if(a[2]>=a[4]*5)
    			a[2]=a[2]-a[4]*5;
    		else
    		{
    			a[1]=max(0,a[1]-(a[4]*5-a[2])*4);
    			a[2]=0;
    		}
    
    		sum+=(a[3]+3)/4;
    		int yu3=a[3]%4;
    		if(yu3==1)
    		{
    			a[2]=max(0,a[2]-5);
    			a[1]=max(0,a[1]-7);
    		}
    		else if(yu3==2)
    		{
    			a[2]=max(0,a[2]-3);
    			a[1]=max(0,a[1]-6);
    		}
    		else if(yu3==3)
    		{
    			a[2]=max(0,a[2]-1);
    			a[1]=max(0,a[1]-5);
    		}
    
    		sum += (a[2]+8)/9;
    		int yu2 = a[2]%9;
    		if(yu2>0)
    			a[1]=max(0,a[1]-(36-yu2*4));
    
    		sum += (a[1]+35)/36;
    		cout<<sum<<endl;
    	}
    	return 0;
    }
    



    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    day06
    day05
    day04
    day03
    day02
    day01
    python-study-42
    OI 知识总览 算法篇 之 图论
    OI 知识总览 算法篇 之 基础算法
    [CSP2019-JX] 散步 解题报告
  • 原文地址:https://www.cnblogs.com/lightspeedsmallson/p/4785794.html
Copyright © 2011-2022 走看看