poj1017——Packets

本文介绍了一种针对特定装箱问题的优化算法实现。通过按产品尺寸从大到小排列并尽可能填满每个6*6的箱子来最小化所需箱子数量。文章详细展示了算法流程,包括如何处理不同尺寸的产品以达到最优填充。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

装包问题。

题意:某公司生产的产品有6种,而只有6*6的箱子可以装。求使用最少的箱子,将产品包装。

思路:按大到小的顺序装,尽量使每个箱子装满!

#include<iostream> #include<cstdio> #include<cstring> using namespace std; int a[8]; int main() { int all,i,time,square; while(1) { all=0; for(i=1;i<=6;i++) { cin>>a[i];all+=a[i]; } if(all==0) break; time =0; time+=a[6]; time+=a[5]; square=a[5]*11; if(a[1]>=square) a[1]-=square; else a[1]=0; time+=a[4]; square=a[4]*20; if(a[2]>=a[4]*5){ a[2]-=a[4]*5; square=0;} else { square-=a[2]*4;a[2]=0;} if(a[1]>=square) a[1]-=square; else a[1]=0; if(a[3]>=4) { time+=a[3]/4; a[3]%=4; } if(a[3]==3) { time++;square=9; if(a[2]>0) { a[2]--;square-=4;} if(a[1]>=square) a[1]-=square; else a[1]=0; } else if(a[3]==2) { time++;square=18; if(a[2]>=3) { square=6;a[2]-=3;} else { square-=a[2]*4; a[2]=0;} if(a[1]>=square) a[1]-=square; else a[1]=0; } else if(a[3]==1) { time++;square=27; if(a[2]>=5) { square=7;a[2]-=5;} else { square-=a[2]*4;a[2]=0;} if(a[1]>=square ) a[1]-=square; else a[1]=0; } if(a[2]>0) { time+=a[2]/9; a[2]%=9; if(a[2]>0) { time++;square=36-a[2]*4; if(a[1]>=square) a[1]-=square; else a[1]=0; } } if(a[1]>0) { time+=a[1]/36; a[1]%=36; if(a[1]>0) { time++; } } cout<<time<<endl; } return 0; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值