文章
85
粉丝
0
获赞
462
访问
9.4k
#include <bits/stdc++.h>
using namespace std;
const int Max = 105;
char MyMap[Max][Max];
int is_visited[Max][Max];
struct node {
int x;
int y;
};
int dir[8][2]={
{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},
{-1,1},{-1,-1}
};
void Dfs(node n,int h,int w) {
int nx = n.x;
int ny = n.y;
is_visited[nx][ny] = 1;
for (int i = 0; i < 8; i++) {
int newx = nx + dir[i][0];
int newy = ny + dir[i][1];
if (newx<0||newx>=h||newy<0||newy>=w) {
continue;
}
if (!is_visited[newx][newy]&&MyMap[newx][newy]!='*') {
Dfs(node{newx,newy},h,w);
}
}
}
int main() {
int h, w;
while(cin>>h>>w) {
if (h==0&&w==0) {
break;
}
memset(is_visited, 0, sizeof(is_visited));
for (int i = 0; i < h; i++) {
scanf("%s", MyMap[i]);
}
int count = 0;
...
登录后发布评论
暂无评论,来抢沙发