| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
简单的dfs就可以了!#include <stdio.h>
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
int times,r,c;
char map[21][21];
void dfs(int s,int e)
{
int i,tempx,tempy;
times++;
map[s][e]='#';
for(i=0;i<4;i++)
{
tempx=s+dx[i];
tempy=e+dy[i];
if(tempx>=1&&tempx<=r&&tempy>=1&&tempy<=c&&map[tempx][tempy]=='.')
dfs(tempx,tempy);
}
}
int main()
{
int i,j,sx,sy;
while(scanf("%d%d",&c,&r)!=EOF&&r&&c)
{
for(i=1;i<=r;i++)
{
getchar();
for(j=1;j<=c;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='@')
{
sx=i;
sy=j;
}
}
}
times=0;
dfs(sx,sy);
printf("%d\n",times);
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator