poj 1017 Packets

#include <iostream>
using namespace std;
int main()
{
int arr[8];
while(cin>>arr[1]>>arr[2]>>arr[3]>>arr[4]>>arr[5]>>arr[6])
{
if(arr[1]+arr[2]+arr[3]+ar r[4]+arr[5]+arr[6]==0)
break;
int pack=0;

pack
+=arr[6]+arr[5];
arr[
1]=arr[1]>arr[5]*11?arr[1]-arr[5]*11:0;

pack
+=arr[4];
if(arr[2]>=arr[4]*5)
arr[
2]-=arr[4]*5;
else
{
int t1=arr[4]*20-arr[2]*4;
arr[
1]=arr[1]>t1?arr[1]-t1:0;
arr[
2]=0;
}

pack
+=arr[3]/4;
arr[
3]%=4;
if(arr[3]>0)
pack
++;
if(arr[3]==1)
{
if(arr[2]>5)
{
arr[
2]-=5;
arr[
1]=arr[1]>7?arr[1]-7:0;
}
else
{
int t2=27-4*arr[2];
arr[
1]=arr[1]>t2?arr[1]-t2:0;
arr[
2]=0;
}
}
else if(arr[3]==2)
{
if(arr[2]>3)
{
arr[
2]-=3;
arr[
1]=arr[1]>6?arr[1]-6:0;
}
else
{
int t2=18-4*arr[2];
arr[
1]=arr[1]>t2?arr[1]-t2:0;
arr[
2]=0;
}
}
else if(arr[3]==3)
{
if(arr[2]>1)
{
arr[
2]-=1;
arr[
1]=arr[1]>5?arr[1]-5:0;
}
else
{
int t2=9-4*arr[2];
arr[
1]=arr[1]>t2?arr[1]-t2:0;
arr[
2]=0;
}
}

pack
+=arr[2]/9;
arr[
2]%=9;
if(arr[2]>0)
{
pack
++;
int t3=36-arr[2]*4;
arr[
1]=arr[1]>t3?arr[1]-t3:0;
}

if(arr[1]>0)
{
pack
+=1+arr[1]/36;
if(arr[1]%36==0)
pack
--;
}

cout
<<pack<<endl;
}
return 0;
}

  

posted on 2011-07-22 16:55  sysu_mjc  阅读(136)  评论(0编辑  收藏  举报

导航