提交时间:2022-07-29 18:02:46

运行 ID: 55023

//1145141919810 #include<bits/stdc++.h> using namespace std; int w,h,ans=0; int a[21][21]={0}; void bfs(int i,int j){ if(a[i][j]!=-1) ans++; a[i][j]=-1; if(i-1&&a[i-1][j]!=1) bfs(i-1,j); if(j-1&&a[i][j-1]!=1) bfs(i,j-1); if(i+1<=w&&a[i+1][j]!=1) bfs(i+1,j); if(j+1<=h&&a[i][j+1]!=1) bfs(i,j+1); } int main(){ int i1,j1; while(1){ ans=0; cin>>w>>h; if(w==0&&h==0) break; for(int i=1;i<=w;i++){ for(int j=1;j<=h;j++){ char c; cin>>c; if(c=='#') a[i][j]=1; if(c=='@') i1=i,j1=j; } } bfs(i1,j1); cout<<ans; } return 0; }