You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
const int N = 55 ;
int g [ N ] [ N ] ;
int st [ N ] [ N ] ;
int n , m ;
int dx [ ] = { 0 , - 1 , 0 , 1 } ; // 左上右上
int dy [ ] = { - 1 , 0 , 1 , 0 } ; // 西北东南 1 2 4 8 二进制位运算, 参考1098_0.cpp
int dfs ( int sx , int sy ) {
st [ sx ] [ sy ] = true ; // 标识此位置已访问过
int ans = 1 ; // 自己贡献一个面积
for ( int i = 0 ; i < 4 ; i + + ) {
int tx = sx + dx [ i ] , ty = sy + dy [ i ] ;
if ( tx = = 0 | | tx > n | | ty = = 0 | | ty > m ) continue ;
if ( st [ tx ] [ ty ] ) continue ;
if ( g [ sx ] [ sy ] > > i & 1 ) continue ; // 自带数位压缩表示法~,有墙
ans + = dfs ( tx , ty ) ; // 孩子们继续贡献面积
}
return ans ; // 我们的总面积
}
int cnt , area ;
int main ( ) {
cin > > n > > m ;
for ( int i = 1 ; i < = n ; i + + )
for ( int j = 1 ; j < = m ; j + + )
cin > > g [ i ] [ j ] ;
for ( int i = 1 ; i < = n ; i + + )
for ( int j = 1 ; j < = m ; j + + )
if ( ! st [ i ] [ j ] ) {
cnt + + ; // 连通块数量
area = max ( area , dfs ( i , j ) ) ; // PK目前的最大面积
}
// 输出结果
printf ( " %d \n %d \n " , cnt , area ) ;
return 0 ;
}