POJ1017 Packets 【贪心】

Packets

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 44505   Accepted: 15032

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

Central Europe 1996

参考自:click

#include <stdio.h>
#include <string.h>

int main() {
    int a, b, c, d, e, f, ans, tmp;
    const int sam[] = {0, 5, 3, 1};
    while(scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f), a|b|c|d|e|f) {
        ans = f + e + d + (c + 3) / 4;
        tmp = d * 5 + sam[c % 4];
        if(b > tmp) ans += (b - tmp + 8) / 9;
        tmp = ans * 36 - f * 36 - e * 25 - d * 16 - c * 9 - b * 4;
        if(a > tmp) ans += (a - tmp + 35) / 36;
        printf("%d\n", ans);
    }
    return 0;
}
时间: 2024-12-28 18:14:43

POJ1017 Packets 【贪心】的相关文章

POJ1017 Packets(贪心算法训练)

Time Limit: 1000MS          Memory Limit: 10000K          Total Submissions: 51306          Accepted: 17391 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 pro

poj-1017 Packets (贪心)

http://poj.org/problem?id=1017 工厂生产高度都为h,长和宽分别是1×1 2×2 3×3 4×4 5×5 6×6的6种规格的方形物品,交给顾客的时候需要包装,包装盒长宽高都为6×6,高度为h,为了减少成本,问至少需要多少包装盒才能把全部物品装进去.每一行有6个数,分别表示1×1  2×2 3×3 4×4 5×5 6×6的物品有多少个. 从大到小处理,先放6×6的放一个就需要一个盒子,在放5×5的,每一个也需要一个盒子,但是还可以放11个1×1的物品,放4×4的物品的时

poj1017 Packets

参考了http://www.cnblogs.com/mycapple/archive/2012/08/23/2652070.html 思路: 贪心. 实现: 1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 5 int main() 6 { 7 int b1, b2, b3, b4, b5, b6; //不同大小的木块个数 8 int nTotal = 0; //最少需要的箱子数目 9 int c1

A - Packets 贪心

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

【贪心】POJ1017:Packets

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

poj 1017 Packets 裸贪心

Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43189   Accepted: 14550 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 alway

UVA311:Packets(贪心)

题目大意:有1*1,2*2,3*3,...六种小包裹,往6*6的箱子里装,给出六种小包裹各自的数量,求出最少用的箱子的个数.贪心,思路还是比较简单的,先从大的开始往小的装.6*6的包裹,每个单独装一个箱子:5*5的包裹,可以和11个1*1的搭配:4*4的包裹,可以喝5个2*2的搭配,如果2*2的不够,则补1*1的个数:...以此类推(注意3*3的有四种搭配方案).这里可以每次优先用2*2的去填,如果2*2的为负了,再用1*1的补正,这样可以简化过程.最后如果1*1的数量为负,则不用处理(原因很简

POJ 1017 Packets【贪心】

POJ 1017 题意: 一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6.  这些产品通常使用一个  6*6*h的长方体包裹包装然后邮寄给客户.因为邮费很贵,所以工厂要想方设法的减小每个订单运送时的包裹数量.他们很需要有一个好的程序帮他们解决这个问题从而节省费用.现在这个程序由你来设计.输入数据输入文件包括几行,每一行代表一个订单.每个订单里的一行包括六个整数,中间用空格隔开,分别为 1

贪心 —— POJ 1017 Packets

对应POJ题目:点击打开链接 Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 46584   Accepted: 15752 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 pro