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.
54 lines
1.1 KiB
54 lines
1.1 KiB
#include <bits/stdc++.h>
|
|
/**
|
|
3
|
|
A B B
|
|
A B A
|
|
B A B
|
|
*/
|
|
using namespace std;
|
|
const int N = 110;
|
|
typedef pair<int, int> PII;
|
|
char a[N][N], b[N][N];
|
|
int n;
|
|
int dx[] = {-1, 0, 1, 0}; //上右下左
|
|
int dy[] = {0, 1, 0, -1}; //上右下左
|
|
int res;
|
|
|
|
void bfs(int x, int y) {
|
|
memcpy(b, a, sizeof a);
|
|
|
|
queue<PII> q;
|
|
int cnt = 0;
|
|
// b[x][y] = 'A';
|
|
q.push({x, y});
|
|
|
|
while (q.size()) {
|
|
auto t = q.front();
|
|
q.pop();
|
|
cnt++;
|
|
for (int i = 0; i < 4; i++) {
|
|
int tx = t.first + dx[i], ty = t.second + dy[i];
|
|
if (tx == 0 || tx > n || ty == 0 || ty > n) continue;
|
|
if (b[tx][ty] == 'A') {
|
|
b[tx][ty] = 'B';
|
|
q.push({tx, ty});
|
|
}
|
|
}
|
|
}
|
|
res = max(res, cnt);
|
|
}
|
|
int main() {
|
|
cin >> n;
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= n; j++)
|
|
cin >> a[i][j];
|
|
|
|
//每个b牌
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= n; j++)
|
|
if (a[i][j] == 'B')
|
|
bfs(i, j);
|
|
|
|
printf("%d\n", res);
|
|
return 0;
|
|
} |