POJ1979

来源:互联网 发布:c语言深度剖析 第二版 编辑:程序博客网 时间:2024/05/20 19:33
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>




#define maxn 40


using namespace std;
char map[maxn][maxn];
bool vis[maxn][maxn];


int  n,m,ans;


void bfs( int x, int y)
{
    if(vis[x][y] || map[x][y] == '#')
      return ;
    ans++;
    vis[x][y] = true;
                   bfs(x-1,y);
        bfs(x,y-1);             bfs(x,y+1);
                   bfs(x+1,y);




}
int main( )
{
    while(scanf("%d%d",&n, &m)!=EOF, n &&m)
   {


    ans = 0;
    int i,j,x,y;
    bool flag = 1;
    memset(map,'#',sizeof(map));
    memset(vis,false,sizeof(vis));


    for(  i = 1; i <= m; i++)
    {
       cin.get();
      for( j = 1; j <= n; j++)
        {
            cin>>map[i][j];
           if(map[i][j] == '@' && flag)
           {
               x = i;
               y = j;
               flag = 0;
           }
       }
    }
    bfs(x,y);
    cout<<ans<<endl;




   }




}
0 0
原创粉丝点击