Packets

Problem Description
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 66. 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
Hint
Source
Central Europe 1996 Central Europe 1996 Central European Regionals 1996

AC代码://最朴素的代码。
//以后绝对不会说时间都去哪里了,因为时间都让粗心大意浪费了。
//这个题就是平面题目,硬是做成了立体的。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
//这个题目的关键点是等高。就是看平面就行。
//填充的时候如果不够,就先用大的填充,再用小的进行填充。
int main()
{
    int a,b,c,d,e,f;
    while(~scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f))
    {
    	//终止条件。
        if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)
            break;
        int sum = 0;//记录所用的盒子的数目。
        
        sum += f;//6

        sum += e;//5 单个用1*1填充。
        if(a>11*e)   //填充后剩余的1*1的个数。
            a -= 11*e;
        else a = 0;

        sum += d;//4 单个先用2*2填充,再用1*1填充。
        b = b-5*d;
        if(b<0)
        {
            if(a>(-b)*4)
                a -= (-b)*4;
            else a = 0;
            b = 0;
        }

        sum += c / 4;//3   就3*3的比较麻烦,其他的都很简单。
        if(c%4==3)
        {
            b -= 1;
            if(b<0)
            {
                if(a>(-b)*4)
                    a -= (-b)*4;
                else a = 0;
                b = 0;
            }
            if(a>5)
                a -= 5;
            else a = 0;
            sum++;
        }
        else if(c%4==2)
        {
            b -= 3;
            if(b<0)
            {
                if(a>(-b)*4)
                    a -= (-b)*4;
                else a = 0;
                b = 0;
            }
            if(a>6)
                a -= 6;
            else a = 0;
            sum++;
        }
        else if(c%4==1)
        {
            b -= 5;
            if(b<0)
            {
                if(a>(-b)*4)
                    a -= (-b)*4;
                else a = 0;
                b = 0;
            }
            if(a>7)
                a -= 7;
            else a = 0;
            sum++;
        }

        sum += (b / 9);//2
        if(b%9!=0)
        {
            if(a>(9-b%9)*4)
                a -= (9-b%9)*4;
            else a = 0;
            sum++;
        }

        sum += a/36;//1
        if(a%36!=0)
        {
            sum++;
            a = 0;
        }
        printf("%d\n",sum);
    }
    return 0;
}

### 详解 你提到的`num_packets`是指红包的数量。在这个场景中,`num_packets`是9,因为每次发放9个红包,总共9元钱。我们将使用这个参数来控制生成红包的数量。 下面是基于你提供的条件(九个红包,九块钱),并结合二倍均值法生成红包金额的详细算法: ### 给出答案(答案为带注释的代码块) ```python import random def generate_red_packets(total_money, num_packets): # 计算平均金额 avg_money = total_money / num_packets # 定义一个列表用于存储每个红包的金额 packets = [] # 剩余金额 remaining_money = total_money for i in range(num_packets - 1): # 生成随机金额,范围为0.01到剩余金额减去剩下红包平均金额的两倍 upper_bound = min(2 * avg_money, remaining_money - (num_packets - i - 1) * 0.01) money = round(random.uniform(0.01, upper_bound), 2) packets.append(money) remaining_money -= money # 最后一个红包分配剩余的所有金额 packets.append(round(remaining_money, 2)) return packets # 设置红包数量和总金额 num_packets = 9 total_money = 9.00 # 调用函数生成9个红包,总共9元 packets = generate_red_packets(total_money, num_packets) print(f"生成的红包金额为: {packets}") ``` ### 代码解析 - `generate_red_packets` 函数接收两个参数:`total_money`(总金额)和`num_packets`(红包数量)。 - 计算每个红包的平均金额`avg_money`,并设定每个红包金额的上限为平均金额的两倍。 - 使用 `for` 循环迭代生成每个红包的金额,确保最后一个红包分配完所有剩余金额。 - 使用 `random.uniform` 生成指定范围内的随机金额,并用 `round` 确保金额精确到小数点后两位。 ### 示例输出 运行此代码可能会得到如下输出(每次运行结果可能不同,因为涉及随机性): ``` 生成的红包金额为: [0.35, 1.24, 0.67, 1.08, 0.83, 1.42, 1.14, 0.83, 1.44] ``` ### 知识点 - **随机数生成**:利用 `random.uniform` 函数生成指定范围内的浮点数。 - **循环结构**:通过 `for` 循环迭代生成每个红包的金额。 - **条件判断**:在生成金额时使用条件判断确保不会超出总金额限制。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值