题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
#include<queue>
using namespace std;
const int N = 51;
int n, m;
int g[N][N];
bool st[N][N];
int bfs(int x, int y)
{
int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
queue<pair<int, int>> q;
q.push({x, y});
st[x][y] = true;
int res = 0;
while(q.size())
{
auto t = q.front();
q.pop();
int x = t.first, y = t.second;
res ++;
for (int i = 0; i < 4; i ++)
{
int a = x + dx[i], b = y + dy[i];
if (a < 0 || a >= n || b < 0 || b >= m) continue;
if (st[a][b]) continue;
if(g[x][y] >> i & 1) continue;
q.push({a, b});
st[a][b] = true;
}
}
return res;
}
int main()
{
cin >> n >> m;
for(int i = 0; i < n; i ++)
for (int j = 0; j < m; j ++)
cin >> g[i][j];
int maxv = 0, cnt = 0;
for (int i = 0; i < n; i ++ )
for (int j = 0; j < m; j ++)
if (!st[i][j])
{
cnt ++;
maxv = max(maxv, bfs(i, j));
}
cout << cnt << endl << maxv;
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla