Metal Steak

Hard to eat

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 79 Stories :: 0 Comments :: 0 Trackbacks

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int
matrix[
101][101], ans, col, row, vst[10001], b[101][101];

void
__read__()
{
    
string str[101];
    cin 
>> row >> col;
    
forint i = 1; i <= row; i++ )
        cin 
>> str[i];
    
forint i = 1; i <= row; i++ )
        
forint j = 0; j <= col; j++ )
            
if( str[i][j] - '0' > 0 )
                matrix[i][j 
+ 1= 1;
}

void
__init__()
{
    
int k = 1;
    
forint i = 1; i <= row; i++ )
        
forint j = 1; j <= col; j++ )
        {
            
if( matrix[i][j] )
                b[i][j] 
= k++;
        }
}

void
change( 
int ori, int tar )
{
    
forint i = 1; i <= row; i++ )
        
forint j = 1; j <= col; j++ )
            
if( b[i][j] == ori )
                b[i][j] 
= tar;
}

void
__dfs__( 
int c, int r, int x )
{
    
if( x <= col * row )
    {
        
if( matrix[r][c] )
        {
            
if( c + 1 <= col )
                
if( matrix[r][c + 1] )
                    change( b[r][c 
+ 1], b[r][c] );

            
if( r + 1 <= row )
                
if( matrix[r + 1][c] )
                    change( b[r 
+ 1][c], b[r][c] );
        }

        
if!( x % col ) )
            __dfs__( 
1, r + 1, x + 1 );
        
else
            __dfs__( c 
+ 1, r, x + 1 );
    }
}

void
__outp__()
{
    
forint i = 1; i <= row; i++ )
        
forint j = 1; j <= col; j++ )
            
if( b[i][j] )
                
if!vst[b[i][j]] )
                {
                    ans
++;
                    vst[b[i][j]] 
= true;
                }
    cout 
<< ans << endl;
}

int
main()
{
    __read__();
    __init__();
    __dfs__( 
111 );
    __outp__();

    
return 0;
}

posted on 2009-09-15 21:15 mad4alcohol 阅读(27) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理