Packets
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 41014   Accepted: 13776

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
#include <stdio.h>
#include <string.h> int main(){
int a,b,c,d,e,f;
int al, bl;
int total;
int tmp; a = b = c = d = e = f = 0; while(1){
total = 0;
tmp = 0;
al = bl = 0;
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;
} /*
6*6
*/
total += f;
/*
5*5
*/
if(e>0){
total += e;
al += 11 * e;
} /*
4*4
*/
if(d>0){
total += d;
bl += 5 * d;
} /*
3*3
*/
if(c > 0){
tmp = (c%4 == 0)? 0:1;
total += (c/4 + tmp);
tmp = c%4;
if(tmp == 1){
al += 7;
bl += 5;
}
else if(tmp == 2){
al += 6;
bl += 3;
}
else if(tmp == 3){
al += 5;
bl += 1;
}
} /*
2 * 2
*/
if(b > 0){
if(b<=bl) {
al += 4 * (bl - b);
bl = 0;
b = 0;
}
else{
b -= bl;
bl = 0;
}
} if(b > 0){
tmp = (b%9 == 0)? 0:1;
total += (b/9 + tmp);
if(b%9 !=0){
al += 36 - 4*(b %9);
}
b = 0;
} al += bl * 4; if(a > 0){
if(a<=al){
a = 0;
}
else{
a = a - al;
}
} tmp = (a%36 == 0)? 0:1;
total += (a/36 + tmp);
printf("%d\n", total);
} return 0;
}

  

[poj解题]1017的更多相关文章

  1. POJ解题经验交流

    感谢范意凯.陈申奥.庞可.杭业晟.王飞飏.周俊豪.沈逸轩等同学的收集整理.   题号:1003 Hangover求1/2+1/3+...1/n的和,问需多少项的和能超过给定的值 类似于Zerojudg ...

  2. 【poj解题】1028

    stack的应用 #include<iostream> #include<stack> #include<stdio.h> #include<stdlib.h ...

  3. 【poj解题】3664

    简单,两次排序 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 500 ...

  4. 【poj解题】3663

    排序, 遍历,需要裁减 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX ...

  5. 【poj解题】1308

    判断一个图是否是一个树,树满足一下2个条件即可:1. 边树比node数少12. 所有node的入度非0即1 节点数是0的时候,空树,合法树~ 代码如下 #include <stdio.h> ...

  6. 洛谷 P1731 [NOI1999]生日蛋糕 && POJ 1190 生日蛋糕

    题目传送门(洛谷)  OR 题目传送门(POJ) 解题思路: 一道搜索题,暴力思路比较容易想出来,但是这道题不剪枝肯定会TLE.所以这道题难点在于如何剪枝. 1.如果当前状态答案已经比我们以前某个状态 ...

  7. POJ 1017

    http://poj.org/problem?id=1017 题意就是有6种规格的物品,给你一些不同规格的物品,要求你装在盒子里,盒子是固定尺寸的也就是6*6,而物品有1*1,2*2,3*3,4*4, ...

  8. POJ 1003 解题报告

    1.问题描述: http://poj.org/problem?id=1003 2.解题思路: 最直观的的想法是看能不能够直接求出一个通项式,然后直接算就好了, 但是这样好水的样子,而且也不知道这个通项 ...

  9. POJ 1004 解题报告

    1.题目描述: http://poj.org/problem?id=1004 2.解题过程 这个题目咋一看很简单,虽然最终要解出来的确也不难,但是还是稍微有些小把戏在里面,其中最大的把戏就是float ...

随机推荐

  1. asp.net无法触发asp控件的后台方法

    前台代码: <asp:Button ID="btnFinish" runat="server" Text="完成" Font-Size ...

  2. Linq序列间的操作

    一.Union并集操作相同的数据只显示一次 二.Concact连接 相同的数据也会重复显示 三.except差集 我有的你没有的显示 四.intersect交集相同的显示 五.zip序列的合并 六.d ...

  3. Windows下的 Axel下载工具 - 移植自Linux

    Axel 是 CLI (command-line interface) 下的一个多线程下载工具,通常我都用它取代 wget 下载各类文件,适用于 Linux 及 BSD 等 UNIX 类平台. 以下是 ...

  4. 关于C++ const

    1.Const用途 No. 用途 使用范围 参考代码 1 类型检查 参数传递 void func(const int i){ ... } 2 节省空间,避免不必要的内存分配 代替#define #de ...

  5. Hibernate 系列教程1-枚举单例类

    你还在为不知道怎样正确使用Hibernate而纠结吗 你还在为不知道怎样配置映射文件而郁闷吗 枚举单例(Enum Singleton) 是实现单例模式的一种方式而已,不过写法简单,创建枚举默认也是线程 ...

  6. thrift概述

    Apache Thrift 是FaceBook实现的一种跨平台的远程服务调用(RPC)的框架.它采用接口描述语言(IDL)定义并创建服务,传输数据采用二进制格式,相对于XML和Json等常用数据传输方 ...

  7. struts2中的<s:select>默认选项

    //... public class SelectAction extends ActionSupport{ private List<String> searchEngine; priv ...

  8. openwrt+ndp+ndppd+radvd+dhcpv6,ipv6穿透配置指南

    要用ipv6首先你的openwrt路由内核必须已经支持ipv6,且能安装相关软件! 首先说说最简单的ndp手工ipv6穿透,很简单,看代码详解: 环境: wan口 eth1 lan口 br-lan w ...

  9. CentOS服务端口开放

    #例如开放81端口iptables -I INPUT -i eth0 -p tcp --dport 81 -j ACCEPTiptables -I OUTPUT -o eth0 -p tcp --sp ...

  10. STL笔记之【map之移除元素】

    //---------------------------------------------------------// 移除map中满足条件的元素//----------------------- ...