| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 22300 | Accepted: 12041 |
Description
Input
Output
Sample Input
6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 11 9 .#......... .#.#######. .#.#.....#. .#.#.###.#. .#.#..@#.#. .#.#####.#. .#.......#. .#########. ........... 11 6 ..#..#..#.. ..#..#..#.. ..#..#..### ..#..#..#@. ..#..#..#.. ..#..#..#.. 7 7 ..#.#.. ..#.#.. ###.### ...@... ###.### ..#.#.. ..#.#.. 0 0
Sample Output
45 59 6 13
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 25
#define MM 10000000
char s[maxn][maxn];
int w[maxn][maxn]; //标记走过的点
int sx,sy;
int conut; //计数
int n,m;
int xx[]={0,0,1,-1};
int yy[]={1,-1,0,0};
int dfs(int x,int y)
{
if(s[x][y]=='#' || w[x][y])
return 0;
conut++;
w[x][y]=1;
for(int i=0;i<4;i++)
{
int xi=x+xx[i];
int yi=y+yy[i];
if(xi>=0 && xi<n && yi>=0 && yi<m)
dfs(xi,yi);
}
return conut;
}
int main()
{
while(~scanf("%d%d",&m,&n))
{
if(m==0 && n==0)
break;
memset(w,0,sizeof(w));
conut=0;
for(int i=0;i<n;i++)
{
scanf("%s",s[i]); //逐行输入
for(int j=0;j<m;j++)
if(s[i][j]=='@')//标记下起点
{
sx=i;
sy=j;
}
}
int k=dfs(sx,sy);
printf("%d\n",k);
}
return 0;
}poj 1979 Red and Black,布布扣,bubuko.com
原文地址:http://blog.csdn.net/u013712847/article/details/38375289