http://poj.org/problem?id=1017
有1*1到6*6的物体,求至少需要几个6*6的箱子装它们。
贪心,先装大再装小。这个写的更清楚。
http://www.hankcs.com/program/cpp/poj-1017-packets.html
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
int ans;
int p1,p2,p3,p4,p5,p6;
int s2,s1;
int a[4]={0,5,3,1};
//一个箱子放入i个3*3后还可以放入几个2*2
int main(){
while (cin >> p1 >> p2 >> p3 >> p4 >> p5 >> p6){
if (p1==0&&p2==0&&p3==0&&p4==0&&p5==0&&p6==0){
break;
}
ans=p4+p5+p6+ceil(p3/4.0);
s2=5*p4+a[p3%4];
//【一个箱子放入一个4*4后还可以放5个2*2】+【一个箱子放入(p3%4)个3*3后可以放入x个2*2】,下同。
if (p2>s2){
ans+=ceil((p2-s2)/9.0);
}
s1=36*ans-36*p6-25*p5-16*p4-9*p3-4*p2;
if (p1>s1){
ans+=ceil((p1-s1)/36.0);
}
cout << ans << endl;
}
}