Packets (poj 1017 贪心)

13 篇文章 0 订阅
Language:
Packets
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 45776 Accepted: 15485

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 

Source

题意: 一个工厂制造的产品形状都是长方体盒子,它们的高度都是 h,长和宽都相等,一共有六个型号,分别为1*1, 2*2, 3*3, 4*4, 5*5, 6*6。

这些产品通常使用一个 6*6*h 的长方体箱子包装然后邮寄给客户。求需要的盒子的最少数量。

贪心,直接模拟吧。。。把情况都考虑到,写的蛋疼。。。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 1005
#define MAXN 2005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FRE(i,a,b)  for(i = a; i <= b; i++)
#define FRL(i,a,b)  for(i = a; i < b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define DBG         pf("Hi\n")
typedef long long ll;
using namespace std;

int a[7];

bool have()
{
    int i;
    FRE(i,1,6)
    if (a[i])
        return true;
    return false;
}

int main()
{
    int i,j;
    while (~sf(a[1]))
    {
        int ans=0;
        int flag=1;
        FRE(i,2,6)
            sf(a[i]);
        FRE(i,1,6)
            if (a[i])
            {
                flag=0;
                break;
            }
        if (flag)
            break;
        int x=0,mm;
        while (have())
        {
            int maxl=6,cnt=36;  //maxl盒子剩下的空间能容纳商品的最大边长,cnt盒子的剩余容量
            for (i=6;i>=1;i--)  //从大的先装
            {
                if (cnt==0) break;  //这个盒子没有容量了
                if(a[i]&&i<=maxl){  
                    if (i<3&&maxl==3){  //主要是盒子原先装了3*3的之后再装2*2比较麻烦
                         if (i==2){
                            if (cnt==27){   //之前已经装了1个3*3
                                mm=min(5,a[i]);
                                a[i]-=mm;
                                cnt-=mm*4;
                            }
                            else if (cnt==18){  //之前已经装了2个3*3
                                mm=min(3,a[i]);
                                a[i]-=mm;
                                cnt-=mm*4;
                            }
                            else if(cnt==9){    //之前已经装了3个3*3
                                mm=min(1,a[i]);
                                a[i]-=mm;
                                cnt-=mm*4;
                            }
                         }
                         else{
                            mm=min(a[i],cnt);
                            a[i]-=mm;
                            cnt-=mm;
                         }
                    }
                    else{
                        if (i==3){
                            mm=min(4,a[i]);
                            a[i]-=mm;
                            cnt-=mm*9;
                            maxl=3;
                        }
                        else if(i>3){
                            a[i]--;
                            cnt-=i*i;
                            maxl=6-i;
                        }
                        else{
                            mm=min(a[i],cnt/(i*i));
                            a[i]-=mm;
                            cnt-=(mm*i*i);
                        }
                    }
                }
            }
            ans++;  //盒子数自增
        }
        pf("%d\n",ans);
    }
    return 0;
}
/*
0 0 4 0 0 1
7 5 1 0 0 0
0 0 0 0 0 0
*/




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值