- 瓷砖
答案
- @ 2026-5-23 13:48:10
#include <bits/stdc++.h>
using namespace std;
bool g[52][52];
int starx,stary;
int ans=0,x,y;
void dfs(int x,int y){
ans++;
g[x][y]=false;
if(g[x-1][y]) dfs(x-1,y);
if(g[x+1][y]) dfs(x+1,y);
if(g[x][y-1]) dfs(x,y-1);
if(g[x][y+1]) dfs(x,y+1);
}
int main(){
int h,w;
char c;
cin>>h>>w;
for(int i=1;i<=w;i++){
for(int j=1;j<=h;j++){
cin>>c;
if(c=='@'){
starx=i;
stary=j;
g[i][j]=true;
}else if(c=='#'){
g[i][j]=false;
}else if(c=='.'){
g[i][j]=true;
}
}
}
dfs(starx,stary);
cout<<ans<<endl;
return 0;
}
0 条评论
目前还没有评论...
信息
- ID
- 1298
- 时间
- ms
- 内存
- MiB
- 难度
- 1
- 标签
- 递交数
- 38
- 已通过
- 17
- 上传者