Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

递归加深搜,测试案例能过,就是WA,大牛帮看看呗~^ ^

Posted by a65982021 at 2012-08-01 09:32:28 on Problem 1562
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator