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

Re:那位帮忙看一下,不知哪错了,谢谢!

Posted by sinper at 2007-09-18 22:28:03 on Problem 1979
In Reply To:那位帮忙看一下,不知哪错了,谢谢! Posted by:chenyy at 2007-08-30 16:34:12
#include <stdio.h>

char map[100][100];
int num;
int dir[4][2] = {{0,-1},{0,1},{1,0},{-1,0}};
int 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++)
            {
                scanf("%c", &map[i][j]);
               if(map[i][j]=='@')
                {
                    si=i;sj=j;
                }
            }
			getchar();
		}
        map[si][sj]='.'; 
        dfs(si,sj);
        printf("%d\n",num);
    }
    return 0;
}
=================================================================
看下我AC的

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