POJ 1017

时间:2023-03-10 07:28:05
POJ 1017

http://poj.org/problem?id=1017

题意就是有6种规格的物品,给你一些不同规格的物品,要求你装在盒子里,盒子是固定尺寸的也就是6*6,而物品有1*1,2*2,3*3,4*4,5*5,6*6,给定你一些物品的数量,求最少的盒子的用量。

思路:对于大的盒子先放,而小的盒子,如果可以填充的话,就填充,也是又大到小填充。分析多种情况即可

 #include <stdio.h>
#include <iostream> using namespace std; int main()
{
int one,two,thr,fou,fiv,six,ans;
while()
{
ans=;
scanf("%d%d%d%d%d%d",&one,&two,&thr,&fou,&fiv,&six);
if(one==&&two==&&thr==&fou==&&fiv==&&six==) break;
ans+=six;
ans+=fiv;
if(fiv!=)
{
if(one<fiv*) one=;
else one-=fiv*;
}
ans+=fou;
if(fou!=)
{
if(two>=fou*) two-=fou*;
else
{
one-=(fou*-two)*;
two=;
}
}
if(thr%==) ans+=thr/;
else
{
ans+=thr/+;
if(thr%==)
if(two>=)
{
two-=;one-=;
}
else
{
one-=(-two*);
two=;
}
if(thr%==)
if(two>=)
{
two-=;one-=;
}
else
{
one-=(-two*);
two=;
}
if(thr%==)
if(two>=)
{
two-=;
one-=;
}
else
{
one-=(-two*);
two=;
}
}
if(two>) {
if(two%==) ans+=two/;
else {
ans+=two/+;
one-=(two/+)*-two*;
}
}
if(one>){
if(one%==) ans+=one/;
else {
ans+=one/+;
}
}
printf("%d\n",ans);
}
return ;
}