练习4 - 装箱问题(代码有点水)

#include <bits/stdc++.h>
#include <cstdlib>   
#include <cstring>  
#include <string>  
#include <queue>   

using namespace std;  

int n[7]={0,0,0,4,0,0,1};
//int n[7]={0,7,5,1,0,0,0};
int total=0;
int s;
int yu=0;
int main()  
{
	//流程图:分析 >> 敲码    ->    !不要用战术上的勤奋掩盖战略上的懒惰!
	//从大小放 
			//6*6
			total += n[6];
			//5*5;
			total+= n[5];
			for(int j=1;j<=n[5];j++){
				s = 36-5*5; 
				n[1] = max(n[1]-s,0);
			}
			
			//4*4
			total+= n[4];	//4*4最多只能1块 
			
			for(int j=1;j<=n[4];j++){
				s = 36-4*4; 
				if(n[2]>=5) n[2]-=5;
				else{s-=n[2] * 4;n[2]==0;}
				n[1] = max(n[1]-s,0);
			}	
			//3*3
			total+= ceil((n[3]*1.0)/4);	//4*4最多只能1块 
			yu = n[3]%4;
			s = 36-3*3*yu;
			int put2[5]={0,5,3,1,0};	//放不同3*3的块,剩下分别可以放几个2*2 
			
			if(n[2] >= put2[yu]){	//剩下的2*2够不够 
				n[2] -= put2[yu];
				s-= put2[yu] * 4;
				n[1] = max(n[1]-s,0);
			}else{
				s-= n[2] * 4;	//2*2全放完 
				n[2] = 0;
				n[1] = max(n[1]-s,0);
			}
			//2*2
			total += ceil((n[2]*1.0)/9);
			yu = n[2]%9;
			s = 36-2*2*yu;
			n[1] = max(n[1]-s,0);
			//1*1;
			total += ceil((n[1]*1.0)/36);
			
	cout << total;
} 

//cout << "输入";  

结果:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值