packets  

时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte
总提交: 27            测试通过: 14

描述

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.

输入

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.

输出

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.

样例输入

0 0 4 0 0 1
7 5 1 0 0 0
0 0 0 0 0 0

样例输出

2
1

题目上传者

crq

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm> using namespace std;
int v[10];
int ava[10];
int cnt = 0; void work() {
cnt = 0;//init
int res;//剩余的
cnt += v[6];//v[6] == 0;
if(v[5]) { //v[5] == 0;
cnt += v[5];
ava[1] += v[5]*11;//ava[1] += 11;!!!
}
if(v[4]) {
cnt += v[4];
ava[2] += v[4] * 5;
}
if(v[3]) {
int tag = true;
cnt += v[3]/4 ;//v[3] < 4; 3*3*4 == 36;
res = v[3]%4; //占用了几个. if(res==0) tag = false;
else cnt++; if(res==1 && tag) {//占用一个3*3
ava[2] += 5;
ava[1] += 7;
tag = false;
}
if(res==2 && tag){//two 3*3
ava[2] += 3;
ava[1] += 6;
tag = false;
}
if(res==3 && tag) {
ava[2] += 1;
ava[1] += 5;
tag = false;
}
}
if(v[2]) {
if(ava[2] >= v[2]) {
ava[1] += (ava[2]-v[2]) * 4;
}
else {
v[2] -= ava[2];
cnt += v[2]/9;//2*2*9 = 36
res = v[2]%9;
if(res != 0) cnt++;
ava[1] += (9-res) * 4;
}
}
if(v[1]) {
if(ava[1]>=v[1]) {
return;
}
else {
v[1] -= ava[1];
cnt += v[1]/36;
res = v[1]%36;
if(res) cnt++;
}
}
return;
} int main()
{
memset(ava, 0, sizeof(ava));
memset(v, 0, sizeof(v));
while(scanf("%d%d%d%d%d%d", &v[1], &v[2], &v[3], &v[4], &v[5], &v[6])==6) {
if(v[0]==v[1] && v[1]==v[2]&&v[2]==v[3]&&v[3]==v[4]&&v[4]==v[5]&&
v[5]==v[6]&&v[6]==0) break;
work();
printf("%d\n", cnt);
memset(ava, 0, sizeof(ava));
memset(v, 0, sizeof(v));
}
return 0;
}

最新文章

  1. Web APi之控制器创建过程及原理解析(八)
  2. iOS 疑难杂症 — — 推送本地国际化 loc-key 本地化失败的问题
  3. hadoop 笔记
  4. JSON value
  5. poj3050
  6. JAVA学习中Swing部分JDialog对话框窗体的简单学习
  7. 用R语言分析我的fitbit计步数据
  8. 微软的技术态度 -- 从其对于CRT的设计考虑说起
  9. Java HashMap 源码解析
  10. Git起步--git安装与初次运行git前配置
  11. ASCII 码表对照 2
  12. jQuery获取Select选择的Text和 Value
  13. 监听UITabBarItem来拦截是否要跳转
  14. mysql数据库在Navicat Premium连接的时候出现1862错误
  15. java离request获取当前从访问完成url至
  16. Ext:添加进度条
  17. LeetCode 665. Non-decreasing Array (不递减数组)
  18. mac连接windows远程桌面及文件复制
  19. 数值计算 的bug:(理论)数学上等价,实际运行未必等价
  20. 关于PID的如何修改的FAQ

热门文章

  1. Android项目代码混淆
  2. 【转】iOS开发系列--数据存取
  3. Xcode7设置生成DSYM出现大量警告
  4. MySQL 创建数据库
  5. 动态插入图片到 svg 中
  6. Java数据库连接池的几种配置方法(以MySQL数据库为例)
  7. jsp &lt;%! %&gt; 与 &lt;% %&gt; 区别
  8. [转载] extern &quot;C&quot;的用法解析
  9. Android动画 fillAfter和fillBefore
  10. Android获取屏幕的高度和宽度