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 skogt at 2010-07-20 10:23:35 on Problem 1979
#include<iostream>
using namespace std;
int dir[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
char str[25][25];
int m,n;
int count;

bool Isok(int a,int b)
{
	if(a<0||b<0||a>n||b>m)
		return false;
	return true;
}
void DFS(int i,int j)
{
	count++;
	str[i][j]='#';
	for(int k=0;k<4;k++)
	{
		int x=i+dir[k][0];
		int y=j+dir[k][1];
		if(Isok(x,y)==true&&str[x][y]=='.')
		{
			DFS(x,y);
		}
	}
}
int main()
{
	int i,j;
	while(scanf("%d%d",&m,&n)==2)
	{
		if(m+n==0)	break;
		count=0;
		for(i=0;i<n;i++)
			scanf("%s",str[i]);
		for(i=0;i<n;i++)
			for(j=0;j<m;j++)
				if(str[i][j]=='@')
				{
					DFS(i,j);
					break;
				}
		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