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 |
那位帮忙看一下,不知哪错了,谢谢!#include<iostream> using namespace std; char map[100][100],num; int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}},n,m; void dfs(int si,int sj) { int x,y,i; if(si>m||sj>n||si<=0||sj<=0)return ; if(map[si][sj]=='.') { num++;map[si][sj]='#'; for(i=0;i<4;i++) { x=si+dir[i][0], y=sj+dir[i][1]; if(map[x][y]=='.') dfs(x,y); } } } int main() { int i,j,si,sj; while(scanf("%d%d",&n,&m)!=EOF&&!(n==0&&m==0)) { getchar();num=0; for(i=1;i<=m;i++) for(j=1;j<=n;j++) { cin>>map[i][j]; if(map[i][j]=='@') { si=i;sj=j; } } map[si][sj]='.'; dfs(si,sj); printf("%d\n",num); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator