tijie
2025-08-29 14:59:19
发布于:北京
0阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int n,m,u=1;
char mp[55][55];
int d[][2]={-1,0,0,1,1,0,0,-1};
void dfs(int x,int y){
for(int i=0;i<4;i++){
int tx=x+d[i][0];
int ty=y+d[i][1];
if(tx>=0 and tx<n and ty>=0 and ty<m and mp[tx][ty]'.'){
u++;
mp[tx][ty]='#';
dfs(tx,ty);
}
}
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>mp[i];
}int s,e;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(mp[i][j]'@'){
s=i;
e=j;
}
}
}
mp[s][e]='#';
dfs(s,e);
cout<<u;
return 0;
}
这里空空如也
有帮助,赞一个