社区讨论
听取wa声一片
P1451求细胞数量参与者 6已保存回复 10
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 8 条
- 当前快照
- 1 份
- 快照标识符
- @lyxsh3xy
- 此快照首次捕获于
- 2024/07/23 10:20 2 年前
- 此快照最后确认于
- 2024/07/23 11:10 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
int n, m, vis[110][110], sum;
int d[4][2] = {{ -1, 0},{ 0, -1},{ 1, 0},{ 0, 1}};
int mp[110][110];
struct node {
int x, y;
} q[110];
void bfs(int x, int y){
int head = 1,tail = 1;
q[tail].x = x;
q[tail].y = y;
tail++;
while(head < tail){
int x1 = q[head].x;
int y1 = q[head].y;
vis[x1][y1] = 1;
for(int i = 0; i < 4; i++){
int nx = x1 + d[i][0];
int ny = y1 + d[i][1];
if(nx >= 0 && nx < n && ny >= 0 && ny < m && mp[nx][ny] != 0 && !vis[nx][ny]){
q[tail].x = nx;
q[tail].y = ny;
tail++;
vis[nx][ny]=1;
}
}
head++;
}
}
int main(){
int i, j;
cin>> n >> m;
for(i = 1; i <= n; i++){
for(j = 1; j <= m; j++){
char ch;
cin >> ch;
mp[i][j] = ch;
bfs(i, j);
}
}
cout << sum;
return 0;
}
回复
共 10 条回复,欢迎继续交流。
正在加载回复...