标签:
Description
Input
Output
Sample Input
Sample Output
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m,ans; char map[25][25]; int yi[4][2]={{1,0},{-1,0},{0,1},{0,-1}}; void dfs(int x,int y) { int i,rx,ry; map[x][y]=‘#‘; ans++; for (i=0;i<4;i++) { rx=x+yi[i][0]; ry=y+yi[i][1]; if (rx>=1&&rx<=n&&ry>=1&&ry<=m&&map[rx][ry]==‘.‘) { dfs(rx,ry); } } } int main() { int i,j,x,y; while (~scanf("%d%d",&m,&n)) { if (n==0&&m==0) break; ans=0; for (i=1;i<=n;i++) for (j=1;j<=m;j++) { scanf(" %c",&map[i][j]); if (map[i][j]==‘@‘) { x=i; y=j; } } dfs(x,y); printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/pblr/p/4696378.html