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 题目大意
就是给你六个数字,从前往后依次代表,i*i类型的箱子,不考虑高度,问你给你最少多少个6*6的箱子
首先意识到,4,5,6单独占一个箱子,3*3的四个占一个箱子,先根据3,4,5,6求出一个大概的数量
之后2就填充3,4占用的箱子空下来的空间,1就占用其他空间。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
int dir[4]={0,5,3,1};
int main()
{
int a[10];
while(1)
{
int sum=0,ans=0;
for(int i=1;i<=6;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(sum==0) break;
ans=(a[3]+3)/4+a[4]+a[5]+a[6];
int cnt_2=a[4]*5+dir[a[3]%4];
if(a[2]>cnt_2)
{
ans+=(8+a[2]-cnt_2)/9;
}
int cnt_1=ans*36-a[3]*9-a[4]*16-a[5]*25-a[6]*36-a[2]*4;
if(a[1]>cnt_1)
{
ans+=(35+a[1]-cnt_1)/36;
}
printf("%d\n",ans);
}
return 0;
}

  

												

A - Packets 贪心的更多相关文章

  1. UVA 311 Packets 贪心+模拟

    题意:有6种箱子,1x1 2x2 3x3 4x4 5x5 6x6,已知每种箱子的数量,要用6x6的箱子把全部箱子都装进去,问需要几个. 一开始以为能箱子套箱子,原来不是... 装箱规则:可以把箱子都看 ...

  2. poi 1017 Packets 贪心+模拟

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 48349   Accepted: 16392 Descrip ...

  3. Poj 1017 Packets(贪心策略)

    一.题目大意: 一个工厂生产的产品用正方形的包裹打包,包裹有相同的高度h和1*1, 2*2, 3*3, 4*4, 5*5, 6*6的尺寸.这些产品经常以产品同样的高度h和6*6的尺寸包袱包装起来运送给 ...

  4. POJ 1O17 Packets [贪心]

    Packets Description A factory produces products packed in square packets of the same height h and of ...

  5. poj 1017 Packets 贪心

    题意:所有货物的高度一样,且其底面积只有六种,分别为1*1 2*2 3*3 4*4 5*5 6*6的,货物的个数依次为p1,p2,p3,p4,p5,p6, 包裹的高度与货物一样,且底面积就为6*6,然 ...

  6. poj 1017 Packets 裸贪心

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43189   Accepted: 14550 Descrip ...

  7. uva311 - Packets(贪心)

    题目:311 - Packets 题目大意:给出1*1, 2*2,3 *3, 4*4, 5*5, 6*6的箱子的个数,如今有若干个6*6的箱子,问最少用多少个箱子能够将给定的箱子都装进去. 解题思路: ...

  8. POJ 1017 Packets【贪心】

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

  9. poj-1017 Packets (贪心)

    http://poj.org/problem?id=1017 工厂生产高度都为h,长和宽分别是1×1 2×2 3×3 4×4 5×5 6×6的6种规格的方形物品,交给顾客的时候需要包装,包装盒长宽高都 ...

随机推荐

  1. c# 关于字段内存排序

    关键字:StructLayout.LayoutKind.Explicit.FieldOffset [StructLayout(LayoutKind.Explicit)] public class AA ...

  2. Android Studio 杀掉当前进程

    android.os.Process.killProcess( android.os.Process.myPid());

  3. T-SQL基础(三)之子查询与表表达式

    子查询 在嵌套查询中,最外面查询结果集返回给调用方,称为外部查询.嵌套在外部查询内的查询称为子查询,子查询的结果集供外部查询使用. 根据是否依赖外部查询,可将子查询分为自包含子查询和相关子查询.自包含 ...

  4. [PHP] 算法-字符串的全排列的PHP实现

    输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 思路: 1.利用递归形成 ...

  5. ES6之Object.assign()详解

    译者按: 这篇博客将介绍ES6新增的Object.assign()方法. 原文: ECMAScript 6: merging objects via Object.assign() 译者: Funde ...

  6. CodeMirror 使用

    codemirror是一款在线代码编辑器,官网:https://codemirror.net/doc/manual.html#overview 使用说明 第一步 安装: npm install cod ...

  7. 消息队列redis

    1.消息队列流程 2.接收用户请求 <?php header("Content-type:text/html;charset=utf-8"); //首先加载redis组键 $ ...

  8. LNMP环境下安装Redis,以及php的redis扩展

    1.下载 sudo wget http://download.redis.io/releases/redis-4.0.9.tar.gz 2.解压 sudo tar zvxf redis-4.0.9.t ...

  9. 06-HTML-表格标签

    <html> <head>  <title>表格标签学习</title>  <meta charset="utf-8"/> ...

  10. K8S Calico

    NetworkPolicy是kubernetes对pod的隔离手段,是宿主机上的一系列iptables规则. Egress 表示出站流量,就是pod作为客户端访问外部服务,pod地址作为源地址.策略可 ...