TOJ 1022

A factory produces products packed in square packets of the same height h and of the sizes 1x1, 2x2, 3x3, 4x4, 5x5, 6x6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6x6. Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number of parcels necessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program.

意思是装箱子,在1x1,2x2,3x3,4x4,5x5,6x6个N个的情况下,最少可以用多少个6x6的箱子装起来。

本来想1A的,还是不够小心啊!WA了两次,最后还是慢慢断点才发现,有一个地方没有在a2==3时没有ans++,导致错误。

#include"iostream"
//#include"stdio.h"
using namespace std;
int main()
{
	
	//freoprn("1022.txt","r",stdin);
	int a1,a2,a3,a4,a5,a6;
	while(cin>>a1>>a2>>a3>>a4>>a5>>a6&&(a1+a2+a3+a4+a5+a6))
	{
		int ans=0,k;
		ans+=a6;
		while(a5--)
		{
			ans++;
			if(a1>=11)
				a1-=11;
			else a1=0;
		}
		while(a4--)
		{
			ans++;
			if(a2>=5)
				a2-=5;
			else
			{
				if(a2){
					k=20-4*a2;
					a2=0;
					if(a1>=k)
						a1-=k;
					else a1=0;
				}
				else{
					if(a1>=20)
						a1-=20;
					else
						a1=0;
				}

			}
			
		}
		if(a3>0){
		ans+=a3/4;
		a3%=4;
		if(a3==1)
		{
			ans++;
			if(a2>=5)
				a2-=5;
			else
				a2=0;
			if(a1>=7)
				a1-=7;
			else 
				a1=0;
		}
		else if(a3==2)
		{
			ans++;
			if(a2>=3)
				a2-=3;
			else
				a2=0;
			if(a1>=6)
				a1-=6;
			else
				a1=0;
		}
		else if(a3==3)
		{
			ans++;
			if(a2>=1)
				a2-=1;
			else a2=0;
			if(a1>=5)
				a1-=5;
			else
				a1=0;
		}
		}
		if(a2>0){
		ans+=a2/9;
		a2%=9;
		if(a2)
		{
			ans++;
			if(a1>=(36-a2*4))
				a1-=(36-a2*4);
			else a1=0;
		}
		}
		if(a1>0){
		ans+=a1/36;
		a1%=36;
		if(a1)
			ans++;
		}
		cout<<ans<<endl;

	}
	return 0;
}

posted @ 2011-05-13 15:29  Ac_smile  阅读(287)  评论(0编辑  收藏  举报