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

小水 贴码留念~~~~

Posted by Heng_Xing at 2011-07-17 21:58:39 on Problem 1979
#include<stdio.h>
int n,m;
char s[21][21];
int visit[21][21];
int count;
void dfs(int x,int y)
{
	visit[x][y]=1;
	if(x-1>0&&!visit[x-1][y]&&s[x-1][y]=='.')
	{
		count++;
		dfs(x-1,y);
	}
	if(y-1>0&&!visit[x][y-1]&&s[x][y-1]=='.')
	{
		count++;
		dfs(x,y-1);
	}
	if(x+1<=n&&!visit[x+1][y]&&s[x+1][y]=='.')
	{
		count++;
		dfs(x+1,y);
	}
	if(y+1<=m&&!visit[x][y+1]&&s[x][y+1]=='.')
	{
		count++;
		dfs(x,y+1);
	}
}
int main (void)
{
	int i,j;
	int x,y;
	while(scanf("%d %d",&m,&n),n!=0||m!=0)
	{
		count=1;
		for(i=1;i<21;i++)
			for(j=1;j<21;j++)
				visit[i][j]=0;
		for(i=1;i<=n;i++)
		{
			getchar();
			for(j=1;j<=m;j++)
			{
				scanf("%c",&s[i][j]);
				if(s[i][j]=='@')
				{
					x=i;
					y=j;
				}
			}
		}
		dfs(x,y);
		printf("%d\n",count);
	}
	return 0;
}

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