poj 1017 Packets

poj 1017 Packets


花了两个多小时才搞出来。

而且代码写的也挺烦的,就是从大到小放,先放6,再放5 ……,剩下的部分放其他小的正方形。

主要就是放3的时候,如果剩下一个3*3可以放1个2*2
                                              剩下两个3*3可以放3个2*2
                                               剩下3个3*3可以放5个2*2

#include < iostream >
#include
< fstream >
using   namespace  std;

int  num[ 7 ];
int  main()
{
    
// ifstream cin("data.txt");
    
// ofstream cout("out.txt");   // 40 942 264 8 6 5
     for (;;)
    {
        
int  i;
        
for (i = 1 ; i <= 6 ; i ++ )
            cin
>> num[i];
        
        
if (num[ 1 ] == 0 && num[ 2 ] == 0 && num[ 3 ] == 0 && num[ 4 ] == 0 && num[ 5 ] == 0 && num[ 6 ] == 0 )
            
break ;
        
        
int  ans = num[ 6 ]; // 6
        ans += num[ 5 ]; // 5
         if (num[ 1 ] >= num[ 5 ] * 11 )  num[ 1 ] -= num[ 5 ] * 11 ;
        
else  num[ 1 ] = 0 ;

        
if (num[ 4 ])
        {
            ans
+= num[ 4 ]; // 4
             if (num[ 2 ] >= num[ 4 ] * 5 )num[ 2 ] -= num[ 4 ] * 5 ;
            
else   
            {
                
int  temp = 4 * (num[ 4 ] * 5 - num[ 2 ]);  // 剩下的装1
                num[ 2 ] = 0 ;
                
if (num[ 1 ] >= temp)  num[ 1 ] -= temp;
                
else  num[ 1 ] = 0 ;
            } 
        }
        
        
// 3
          if (num[ 3 ])
         {
            ans
+= (num[ 3 ] + 3 ) / 4 ;
            
int  box3 = 4 - num[ 3 ] % 4 // 剩下的3*3的个数
             if (box3 == 4 )box3 = 0 ;
            
if (box3 == 2 )
            {
                
int  t;
                
if (num[ 2 ] > 3 ){ num[ 2 ] -= 3 ; t = 3 ;}
                
else  {  t = num[ 2 ]; num[ 2 ] = 0 ;}
                
if (num[ 1 ] >= box3 * 9 - t * 4 )num[ 1 ] -= ( box3 * 9 - t * 4 ) ;
                
else  num[ 1 ] = 0 ;
            }
            
else   if (box3 != 0
            {
                
if (box3 == 1 )
                {
                    
if (num[ 2 ] == 0 )
                    {
                        
if (num[ 1 ] >= 9 )num[ 1 ] -= 9 ;
                        
else  num[ 1 ] = 0 ;
                    }
                    
else
                    {
                        num[
2 ] -= 1 ;
                        
if (num[ 1 ] >= 5 )num[ 1 ] -= 5 ;
                        
else  num[ 1 ] = 0 ;
                    }
                }
                
else    // box3==3
                {
                    
int  tt;
                    
if (num[ 2 ] >= 5 ){  num[ 2 ] -= 5 ; tt = 5 ;}
                    
else  { tt = num[ 2 ]; num[ 2 ] = 0 ; } 
                    
if (num[ 1 ] >= box3 * 9 - tt * 4 )num[ 1 ] -= (box3 * 9 - tt * 4 );
                    
else  num[ 1 ] = 0 ;
                }
            }
            
         }
    
         
// 2
          if (num[ 2 ])
         {
          ans
+= (num[ 2 ] + 8 ) / 9 ;
          
int  box2 = 9 - num[ 2 ] % 9 ;
          
if (box2 == 9 )box2 = 0 ;
          
if (num[ 1 ] >= box2 * 4 )num[ 1 ] -= box2 * 4 ;
          
else  num[ 1 ] = 0 ;
         }
         
// 1
          if (num[ 1 ])
         {
                ans
+= (num[ 1 ] + 35 ) / 36 ;
         }
         
         cout
<< ans << endl;
    }

    
return   0 ;
}





 

你可能感兴趣的:(poj 1017 Packets)