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 |
Re:递归加深搜,测试案例能过,就是WA,大牛帮看看呗~^ ^In Reply To:递归加深搜,测试案例能过,就是WA,大牛帮看看呗~^ ^ Posted by:a65982021 at 2012-08-01 09:32:28 > #include<iostream> > using namespace std; > char map[200][200]; > int count; > int m,n; > void dfs(int i,int j) > { > if(map[i][j]=='*'||i<0||j<0||i>m||j>n) > return; > map[i][j]='*'; > dfs(i-1,j-1); > dfs(i-1,j); > dfs(i-1,j+1); > dfs(i,j-1); > dfs(i,j+1); > dfs(i+1,j-1); > dfs(i+1,j); > dfs(i+1,j+1); > } > int main() > { > > int i,j; > while(scanf("%d%d",&m,&n)&&m!=0) > { > count=0; > while(getchar()==' '); > memset(map,'*',sizeof(map)); > for(i=0;i<m;i++) > scanf("%s",&map[i]); > for(i=0;i<m;i++) > for(j=0;j<n;j++) > { > if(map[i][j]=='@') > { > dfs(i,j); > count++; > } > } > printf("%d\n",count); > } > return 1; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator