poj-1017-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.

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 
题目大意:

工厂生产的产品装在方形包的同一高度h和大小的1 * 1,2 * 2,3 * 3,4 * 4,5 * 5,6 * 6。广场上的这些产品总是交付给客户的包裹一样高h的产品和尺寸6 * 6。因为费用是工厂的利益以及客户的包裹需要交付的数量降到最低订购了产品从工厂到客户。一个好的程序解决问题找到所需的最小数量的包裹交付给产品根据订单会省下一大笔钱。你被要求做这样的一个程序。

 

输入

 

输入文件包含几行指定命令。每一行指定一个秩序。订单描述六个整数隔开一个空间代表先后个体大小的数据包的数量从最小的大小1 * 1的最大尺寸6 * 6。输入文件的结束由线表示包含六个零。

 

输出

 

输出文件包含一行输入文件中的每一行。这一行包含订单的最小数量的包裹从相应的输入文件可以包装。没有线相对应的输出文件的最后一个“零”行输入文件。

#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f&&(a+b+c+d+e+f))
    {
      int sum=0;
      sum=f;
      sum+=e;
      if(a!=0)
        a=max(0,a-11*e);//一个包装箱能放1个5*5的盒子和11个1*1的盒子
      sum+=d;

      if(b>=d*5)//一个包装箱只能放1个4*4盒子和5个2*2盒子

      b=b-d*5;
      else
      {
          a=max(0,a-4*(d*5-b));//2*2盒子不够的空间用1*1的盒子补
          b=0;
      }
      sum+=(c+3)/4;//小技巧  相当于向上取整
      c%=4;
      if(c)
  {
      if(b>=7-2*c)//c盒子为:1,2,3,则b盒子为5,3,1得7-2*c关系式
        {
            b-=7-2*c;
            a=max(0,a-(8-c));//尽可能多的放置2*2盒子   放完后放1*1盒子{c:1,2,3;   b:5,3,1    a:7,6,5(填充的箱子需求数)}
     } else
      {
          a=max(0,a-(36-4*b-9*c));
          b=0;
      }

  }
  sum+=(b+8)/9;
  b%=9;
  if(b)
  {
  a=max(0,a-(36-b*4));
  b=0;

  }
sum+=(a+35)/36;
cout<<sum<<endl;


    }



    return 0;
}
相关文章
|
Ubuntu Python
全网最简约的Vscode配置Anaconda环境(百分百成功)
全网最简约的Vscode配置Anaconda环境(百分百成功)
29459 0
全网最简约的Vscode配置Anaconda环境(百分百成功)
|
计算机视觉 Python
OpenCV中阈值处理函数和二值化、反二值化的讲解及实战(附Python源码)
OpenCV中阈值处理函数和二值化、反二值化的讲解及实战(附Python源码)
734 0
|
Ubuntu Linux 虚拟化
虚拟机的 Ubuntu 没有 /dev/fb0 的解决办法
虚拟机的 Ubuntu 没有 /dev/fb0 的解决办法
861 0
虚拟机的 Ubuntu 没有 /dev/fb0 的解决办法
|
6天前
|
存储 关系型数据库 分布式数据库
PostgreSQL 18 发布,快来 PolarDB 尝鲜!
PostgreSQL 18 发布,PolarDB for PostgreSQL 全面兼容。新版本支持异步I/O、UUIDv7、虚拟生成列、逻辑复制增强及OAuth认证,显著提升性能与安全。PolarDB-PG 18 支持存算分离架构,融合海量弹性存储与极致计算性能,搭配丰富插件生态,为企业提供高效、稳定、灵活的云数据库解决方案,助力企业数字化转型如虎添翼!
|
17天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1320 7
|
5天前
|
存储 人工智能 Java
AI 超级智能体全栈项目阶段二:Prompt 优化技巧与学术分析 AI 应用开发实现上下文联系多轮对话
本文讲解 Prompt 基本概念与 10 个优化技巧,结合学术分析 AI 应用的需求分析、设计方案,介绍 Spring AI 中 ChatClient 及 Advisors 的使用。
297 129
AI 超级智能体全栈项目阶段二:Prompt 优化技巧与学术分析 AI 应用开发实现上下文联系多轮对话
|
4天前
|
监控 JavaScript Java
基于大模型技术的反欺诈知识问答系统
随着互联网与金融科技发展,网络欺诈频发,构建高效反欺诈平台成为迫切需求。本文基于Java、Vue.js、Spring Boot与MySQL技术,设计实现集欺诈识别、宣传教育、用户互动于一体的反欺诈系统,提升公众防范意识,助力企业合规与用户权益保护。