1、简单描述
所有商品和箱子的高都相同,商品规格1*1,2*2,3*3,4*4,5*5,6*6,所有的商品都要用6*6规格的箱子来装。最少用多少个箱子来装?
2、思路
数组key【i】是一个箱子放i个3*3的商品,能放下的2*2的商品个数。
贪心,先放大的,再在空余位置放小的。
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
int key[4]={0,5,3,1};
int main()
{
ll box[6];
while(1)
{
int sum=0;
for(int i=1;i<=6;i++)
{
scanf("%lld", &box[i]);
sum += box[i];
}
if(sum == 0)
break;
ll answer = box[6] + box[5] + box[4] + (box[3] + 3)/4;
ll num2 =box[4]*5 + key[box[3] % 4];
if(box[2] > num2)
answer += (box[2] - num2 + 8) / 9;
ll num1=36*answer-36*box[6]-25*box[5]-16*box[4]-9*box[3]-4*box[2];
if(box[1] > num1)
answer += (box[1] - num1 + 35) / 36;
printf("%lld\n",answer);
}
return 0;
}
提交了好几遍超时,一遍wa,虽然,到现在我也没看出a了的这个程序跟wa的那个有什么区别。