标签:贪心
题目链接:http://poj.org/problem?id=1017
Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 44985 | Accepted: 15208 |
Description
Input
Output
Sample Input
0 0 4 0 0 1 7 5 1 0 0 0 0 0 0 0 0 0
Sample Output
2 1
Source
大致题意:一个工厂用6种不同 size 的包装来包装产品 ,分别为 h*1*1, h* 2*2, h*3*3, h*4*4 , h*5*5 , h* 6*6;(这个地方 h可以默认为1 ,没有影响) 我现在要用一个 h*6*6 的大盒子将 这些产品包装在一起,那么问所用大盒子的数量最少为多少?(也就是说许多小盒子放到一个大盒子里面,要求最少数量的大盒子)题意分析: (1)如果小盒子的规模是6*6的,那么肯定得占用一个 完全大盒子,对吧
(2)如果小盒子的规模是5*5的,那么也得占用一个大盒子,但是还会多出来一部分地方,可以分析发现多出来的这一部分只能放 1*1的小盒子
(3)如果小盒子的规模是4*4的,那么也得占用一个大盒子,多出来的一个分可以放 5个规模为 2*2的小盒子,和7个1*1的小盒子
(4)如果小盒子的规模是3*3的,这个地方得分情况讨论,将规模为3*3的小盒子数量 对 4 取余,观察余数可知道 剩余部分怎么分配
另外还有个地方得注意: 2*2能放置的位置 一定能放置4个1*1,但是4个1*1能放置的地方不一定能放置1个2*2的小盒子;
#include <iostream> #include <stdio.h> #include <string> #include <string.h> #include <algorithm> using namespace std; int main() { int a,b,c,d,e,f; while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)!=EOF) { if(a+b+c+d+e+f==0)break; int cnt=0,tmp=0; cnt+=f; //统计多少个 6*6的箱子 cnt+=e; a-=e*11;//统计多少个 5*5的箱子,同时将剩余空间转化为1*1 cnt+=d; //统计多少个4*4的箱子,同时将剩余空间转化为 2*2 if(b>=d*5)b-=d*5; else {tmp+=d*5-b,b=0;} if( c%4 == 0 ) cnt+=c/4; else {cnt+=c/4+1; c=c%4;} if(c==3) { a-=5; if(b>=1)b-=1; else if (b<=0) {tmp+=1;} } else if(c==2) {a-=6; if(b>=3)b-=3; else if(b<=0)tmp+=3; else {tmp+=3-b,b=0;} } else if(c==1) {a-=7; if(b>=5)b-=5; else if(b<=0)tmp+=5; else {tmp+=5-b,b=0;} } if( b>0 ) { if( b%9 == 0)cnt+=b/9; else { cnt+=b/9+1; a-=(36-(b%9)*4); } } a-=tmp*4; if( a>0 ) { if( a%36 == 0)cnt+=a/36; else { cnt+=a/36+1; } } printf("%d\n",cnt); } return 0; }
标签:贪心
原文地址:http://blog.csdn.net/liusuangeng/article/details/41981635