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;
}

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

最新文章

  1. SQL Server 权限管理
  2. 看看Parallel中高度封装的三个方法,Invoke,For和ForEach
  3. Collections操作实例
  4. C# XML读写实例
  5. A - Oulipo
  6. 【学习笔记】【C语言】自增自减
  7. MyEclipse激活失败,解决办法
  8. rabibtMQ安装及集群配置-linux
  9. HashSet、LinkedHashSet、TreeSet使用区别
  10. &amp;与&amp;&amp; C语言
  11. JS学习一
  12. Spring+SpringMVC+MyBatis+easyUI整合优化篇
  13. react-router 4实现代码分割(code spliting)
  14. python基础day3
  15. dubbo和dubboX与微服务架构(dubbo一)
  16. go 函数类型
  17. ES6躬行记(2)——扩展运算符和剩余参数
  18. Maven项目运行Junit测试用例 出现ClassNotFound
  19. R12.1.3 &amp; R12.2.X 注册客户化应用
  20. java 基础-思维导图

热门文章

  1. Kubernetes 各版本镜像列表
  2. Codeforces 546 E:士兵的旅行 最大网络流
  3. endnote的使用
  4. 功耗极低非接触 13.56mhz读卡芯片:SI522
  5. java字符,字符串,数字之间的转换
  6. Spring MVC RedirectAttributes取值方法
  7. JS在不改变原数组的情况下复制一个新的数组
  8. Rails 第一课:环境配置 Ruby Rails RVM Heroku
  9. 图片字节流生成bmp文件
  10. js里事件传播流程