Problem 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
题意:有六种规格的货物,1*1, 2*2 ,3*3, 4*4 ,5*5
,6*6装货物的箱子只有6*6的,求用的最小箱子数;
解题思路:刚开始还以为箱子都是立体的,***(自己体会)!,写到装3*3的时候就不会写了,今早上一看题,才发现昨晚自己瞎了,既然是二维的就好做了,假期看的书里有过这到题,当时看了一点,有点印象,从6*6到1*1贪心,6
,5 ,4的只能装一个,5 的还能装1的,4的还能装1 2的,3的比较麻烦能装1 2 3的,一个个的讨论,剩下1
2的,判断是否大于零就行了,因为装起来比较简单;
感悟:这道题做完比较有成就感,因为测试了很多数据,一个个的BUG改,真爽啊;
测试数据:
Input:

0 0 4 0 0 1

7 5 1 0 0 0

36 9 4 1 1 1

0 9 4 1 1 0

0 0 4 0 0 0

36 0 0 0 0 0

0 9 0 0 0 0

79 96 94 30 18 14

53 17 12 98 76 54

83 44 47 42 80 3

15 26 13 29 42 40

41 61 36 90 54 66

78 56 445 45 23 65

13 4 8 29 45 3

15 75 45 98 34 53

40 9 0 2 0 0

41 9 0 2 0 0

44 0 0 0 4 0

0 2 3 0 0 0

37 7 2 0 1 0

12 2 0 1 0 0

13 2 0 1 0 0

0 0 0 0 0 0



Output:

2

1

6

4

1

1

1

86

231

137

115

219

245

79

197

3

4

4

2

3

1

2
代码:
#include

#include

#include

using namespace std;

int main()

{

   
//freopen("in.txt", "r", stdin);

    int
ans[7]={0},sizen[7]={0,1,2,3,4,5,6};

    int
null=0;

   
while(~scanf("%d%d%d%d%d%d",&ans[1],&ans[2],&ans[3],&ans[4],&ans[5],&ans[6]))

{

       
if(ans[1]==0&&ans[2]==0&&ans[3]==0&&ans[4]==0&&ans[5]==0&&ans[6]==0)

break;

       
null=0;

       
null+=ans[6];//因为装了6*6的就没有别的空间了;


       
//装5*5的东西

       
null+=ans[5];//一个5*5的肯定需要一个箱子装

       
if(ans[1]<=11*ans[5])//还有空装1*1的盒子不要浪费

       
{

           
ans[1]=0;

       
}

       
else

       
{

           
ans[1]-=11*ans[5];

       
}

       
//printf("null=%d\n",null);

       
//printf("a[1]=%d a[2]=%d a[3]=%d a[4]=%d a[5]=%d
a[6]=%d\n",ans[1],ans[2],ans[3],ans[4],ans[5],ans[6]);

       
//装4*4的东西

       
null+=ans[4];//一个4*4的肯定需要一个箱子装,余下的能成5个2*2

       
//或20个1*1的

       
int content=20*ans[4];//这是剩余的盒子空间;

       
if(ans[2]<=5*ans[4])//先装2*2的盒子

       
{

           
int content=20*ans[4];//这是剩余的盒子空间;

           
content-=ans[2]*4;//剩下的体积

           
if(ans[1]<=content)//现在装1*1的盒子

           
{

               
ans[1]=0;

           
}

           
else

           
{

               
ans[1]-=content;

           
}//剩下几平方米就能装几个1*1的;

           
ans[2]=0;

       
}

       
else

       
{

           
ans[2]-=5*ans[4];

       
}

       
ans[4]=0;

       
//printf("null=%d\n",null);

       
//printf("a[1]=%d a[2]=%d a[3]=%d a[4]=%d a[5]=%d
a[6]=%d\n",ans[1],ans[2],ans[3],ans[4],ans[5],ans[6]);

       
//装3*3的

       
null+=ans[3]/4;

       
ans[3]=ans[3]%4;//每四个3*3能装满一个箱子;

       
if(ans[3]>0)

       
{

           
null+=1;

           
if(ans[2]<=7-ans[3]*2)//先装2*2的盒子

           
{

               
int content=36-ans[3]*9-ans[2]*4;//这是剩余的盒子空间;

               
if(ans[1]<=content)//现在装1*1的盒子

               
{

                   
ans[1]=0;

               
}

               
else

               
{

                   
ans[1]-=content;

               
}//剩下几平方米就能装几个1*1的;

               
ans[2]=0;

           
}

           
else

           
{

               
int content=36-ans[3]*9-(7-ans[3]*2)*4;

               
if(ans[1]<=content)//现在装1*1的盒子

               
{

                   
ans[1]=0;

               
}

               
else

               
{

                   
ans[1]-=content;

               
}//剩下几平方米就能装几个1*1的;

               
ans[2]-=(7-ans[3]*2);

           
}

           
ans[3]=0;

           
//printf("null=%d\n",null);

           
//printf("a[1]=%d a[2]=%d a[3]=%d a[4]=%d a[5]=%d
a[6]=%d\n",ans[1],ans[2],ans[3],ans[4],ans[5],ans[6]);

       
}

       
//装2*2的

       
if(ans[2]>0)

       
{

           
null+=ans[2]/9;

           
ans[2]%=9;

           
if(ans[2]>0)

           
{

               
null+=1;

               
int content=36-ans[2]*4;

               
if(ans[1]<=content)//现在装1*1的盒子

               
{

                   
ans[1]=0;

               
}

               
else

               
{

                   
ans[1]-=content;

               
}//剩下几平方米就能装几个1*1的;

           
}

           
ans[2]=0;

           
//printf("null=%d\n",null);

           
//printf("a[1]=%d a[2]=%d a[3]=%d a[4]=%d a[5]=%d
a[6]=%d\n",ans[1],ans[2],ans[3],ans[4],ans[5],ans[6]);

       
}

       
//装1*1的

       
if(ans[1]>0)

       
{

           
null+=ans[1]/36;

           
ans[1]%=36;

           
if(ans[1])

               
null+=1;

           
ans[1]=0;

           
//printf("null=%d\n",null);

           
//printf("a[1]=%d a[2]=%d a[3]=%d a[4]=%d a[5]=%d
a[6]=%d\n",ans[1],ans[2],ans[3],ans[4],ans[5],ans[6]);

       
}

       
printf("%d\n",null);

    }

}


Problem Q的更多相关文章

  1. Problem Q: C语言习题 计算该日在本年中是第几天

    Problem Q: C语言习题 计算该日在本年中是第几天 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 4572  Solved: 2474[Subm ...

  2. 1249 Problem Q

    问题 Q: 比大小 时间限制: 1 Sec  内存限制: 128 MB 提交: 159  解决: 66 [提交][状态][讨论版] 题目描述 给你两个很大的数,你能不能判断出他们两个数的大小呢? 比如 ...

  3. Problem Q: 多项式求和x+(x^2)/2!+(x^3)/3!+...

    #include<stdio.h> #include<math.h> int main() { float x,i; scanf("%f",&x); ...

  4. Problem Q: 零起点学算法12——求2个日期之间的天数

    #include<stdio.h> int main() { int a1,b1,c1,a2,b2,c2,s; scanf("%d-%d-%d",&a1,&am ...

  5. 证明与计算(1): Decision Problem, Formal Language L, P and NP

    0x01 从判定问题到形式语言 这篇讲知识证明的wiki([1]): https://en.wikipedia.org/wiki/Proof_of_knowledge 里面有一句话: Let x be ...

  6. Q - Phalanx

    题目链接:https://vjudge.net/contest/68966#problem/Q 分析:这里的对称并不是指的是关于原矩阵(也就是最大的那一个)主对角线对称,而是对于每一个小的矩阵来说,当 ...

  7. 二分图水一波~~~~d带你飞

    Current Time: 2016-03-11 17:45:36 Contest Type: Public Start Time: 2016-03-04 13:00:00 Contest Statu ...

  8. 菜鸟带你飞______DP基础26道水题

    DP 158:11:22 1205:00:00   Overview Problem Status Rank (56) Discuss Current Time: 2015-11-26 19:11:2 ...

  9. [kuangbin带你飞]专题二十 斜率DP

            ID Origin Title   20 / 60 Problem A HDU 3507 Print Article   13 / 19 Problem B HDU 2829 Lawr ...

随机推荐

  1. python实现算24的算法

    1.介绍 给定4个整数,数字范围在1-13之间,任意使用 + - * / ( ) ,构造出一个表达式,使得最终结果为24,这就是常见的算24的游戏.本文介绍用Python语言实现的两种方式.2.实现思 ...

  2. Angular2响应式表单

    本文将半翻译半总结的讲讲ng2官网的另一个未翻译高级教程页面. 原文地址. 文章目的是使用ng2提供的响应式表单技术快速搭出功能完善丰富的界面表单组件. 响应式表单是一项响应式风格的ng2技术,本文将 ...

  3. Ubuntu Docker 版本的更新与安装

    突然发现自己的docker 版本特别的低,目前是1.9.1 属于古董级别的了,想更新一下最新版本,这样最新的一下命令就可以被支持.研究了半天都没有更新成功,更新后的版本始终都是1.9.1 :蒙圈了,找 ...

  4. PBOC圈存时用到3DES加密解密以及MAC计算方法

    最近在做PBOC圈存时用到了3DES的加密解密以及MAC计算问题,在网上了解一些知识,复制了一些demo学习,我这里没有深入研究,只是把我用到的和了解的做个总结,便于以后使用和学习. 3DES分双倍长 ...

  5. 基于Redis位图实现系统用户登录统计

    项目需求,试着写了一个简单登录统计,基本功能都实现了,日志数据量小.具体性能没有进行测试~ 记录下开发过程与代码,留着以后改进! 1. 需求 1. 实现记录用户哪天进行了登录,每天只记录是否登录过,重 ...

  6. 组件 layui 表单抓取数据四步走

    注意事项: layui 中提交按钮是基于"监听"机制实现的. form.on() 的调用需置于 layui.use 的回调函数中. 末尾的 'return false' 不可或缺, ...

  7. AVPlayer缓存实现

    没有任何工具能适用于所有的场景,在使用AVPlayer的过程中,我们会发现它有很多局限性,比如播放网络音乐时,往往不能控制其内部播放逻辑,比如我们会发现播放时seek会失败,数据加载完毕后不能获取到数 ...

  8. python随机生成中文字符

    第一种方法:Unicode码 在unicode码中,汉字的范围是(0x4E00, 9FBF) import random def Unicode(): val = random.randint(0x4 ...

  9. CSS之 float 属性

    特性: float的设计初衷仅仅是文字环绕效果  浮动具有破坏性,会使父容器高度塌陷  清除浮动方法: 1.脚底插入cleart:both 2.父元素BFC(IE8+)/haslayout(IE6/7 ...

  10. python之集合

    集合(set),它是一个无序的,不重复的数据组合,它是作用如下: 1.去重,也就是去除重复的内容.有一点值得注意的是:将一个列表(list)变成集合的时候,会自动去重. 2.关系测试.测试数据之间的交 ...