AC

sb  •  1年前


include<bits/stdc++.h>

using namespace std; int w,h,ans; bool k[55][55]; void dfs(int x,int y){

ans++;
k[x][y]=0;
if(k[x+1][y]==1) dfs(x+1,y);
if(k[x-1][y]==1) dfs(x-1,y);
if(k[x][y+1]==1) dfs(x,y+1);
if(k[x][y-1]==1) dfs(x,y-1);
return ;

} int main(){

char s;
int x,y;
cin>>h>>w;
for(int i=1;i<=w;i++)
	for(int j=1;j<=h;j++){
		cin>>s;
		if(s=='@'){
			x=i; y=j;
			k[i][j]=1;
		}
		else if(s=='.')
			k[i][j]=1;
	}	
dfs(x,y);
cout<<ans;
return 0;

}


评论:

请先登录,才能进行评论