joj 1349 Oil Deposits: a waste of time in debug 深搜 调试了一小时只因为把=写成了==!

joj 1349 Oil Deposits: a waste of time in debug 深搜 调试了一小时只因为把=写成了==!

 

#include < iostream >
#include
< cstdlib >
using   namespace  std;
int  MATRIX[ 100 ][ 100 ];
int  fx[ 8 ] = { 0 , 0 , 1 , - 1 , 1 , 1 , - 1 , - 1 },fy[ 8 ] = { 1 , - 1 , 0 , 0 , - 1 , 1 , - 1 , 1 };
int  row,col;
  
int  ISALL()
  {
      
int  i,j,mark = 1 ;
      
for (i = 0 ;i < row;i ++ )
       {
       
for (j = 0 ;j < col;j ++ )
       {
           
if (MATRIX[i][j] == 1 )
             mark
= 0 ;              
       }
       }
       
return  mark;
  }
  
int   check( int  i, int  j, int  k)
  {
      
int  f = 1 ;
      
if ((i < 0 || i >= row) || (j < 0 || j >= col))
       f
= 0 ;
      
return  f;
  }
  
void  dfs( int  i, int  j)
  {
       
int  newx,newy;
       
for ( int  k = 0 ;k < 8 ;k ++ )
       {
         newx
= i + fx[k];
         newy
= j + fy[k];      
         
if (check(newx,newy,k) == 1 && MATRIX[newx][newy] == 1 )
         {
             MATRIX[newx][newy]
=- 1 ;                                            
             dfs(newx,newy);              
         }              
       }
  }
  
int  main()
  {
  freopen(
" s.txt " , " r " ,stdin);
  freopen(
" key.txt " , " w " ,stdout);
  
int  flag,times;
  
int  i,j;
  
char  m;
  cin
>> row >> col;
  
while (row != 0 )
  {
    memset(MATRIX,
0 , sizeof (MATRIX));           
    
for (i = 0 ;i < row;i ++ )
    
for (j = 0 ;j < col;j ++ )
    {
      cin
>> m;
      
if (m == ' @ ' )MATRIX[i][j] = 1 ; // ÓÃ1±íʾ@ ,0±íʾ*,·ÃÎÊÖ®ºó¸ÄΪ-1               
    } 
    flag
= times = 0 ;
    
for (i = 0 ;i < row && flag == 0 ;i ++ )
    
for (j = 0 ;j < col && flag == 0 ;j ++ )
    {
        
if (MATRIX[i][j] == 1 )
        {
          MATRIX[i][j]
=- 1 ;                 
          dfs(i,j);
          times
++ ;
         
if (ISALL() == 1 )flag = 1 ;   
         }
                    
    }  
    cout
<< times << endl;        
    cin
>> row >> col;           
  }

  
// system("PAUSE");
   return     0 ;
  }

你可能感兴趣的:(joj 1349 Oil Deposits: a waste of time in debug 深搜 调试了一小时只因为把=写成了==!)