LightOJ1012-Guilty Prince

http://lightoj.com/volume_showproblem.php?problem=1012

有木有发现和之前一道是一样的- -#

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
bool map[21][21];
int cnt,w,h;
void dfs(int x,int y)
{
    if(x>0&x<=w&&y>0&&y<=h&&!map[x][y])
    {
        ++cnt;
        map[x][y]=true;
        dfs(x+1,y);
        dfs(x,y+1);
        dfs(x-1,y);
        dfs(x,y-1);
    }
}
int main(void)
{
    int T,x,y,i,j,t;
    cin>>T;
    for(t=1;t<=T;t++)
    {
        memset(map,0,sizeof(map));
        cnt=0;
        scanf("%d%d",&w,&h);
        for(j=1;j<=h;j++)
           for(i=1;i<=w;i++)
           {
                  char c;cin>>c;
               if(c=='#')
                  map[i][j]=true;
               if(c=='@')
                  x=i,y=j;
            }
        dfs(x,y);
        printf("Case %d: ",t);
        printf("%d\n",cnt);
    }
    return 0;
}
posted @ 2012-08-29 15:59  Yogurt Shen  阅读(269)  评论(0编辑  收藏  举报