#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 << "输入";
练习4 - 装箱问题(代码有点水)
最新推荐文章于 2024-06-14 21:13:33 发布