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 LKC at 2014-10-02 21:48:26 on Problem 1979
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
#define MAX 30
int W,H;
char Graph[MAX][MAX];
int result=0;
int direction[4][2]={{0,1},{0,-1},{-1,0},{1,0}};  


void DFS(int p,int q)
{
	int i;
	if(p>=0 &&p<=W-1 &&q>=0 &&q<=H-1 &&Graph[p][q]=='.')
	{
		result++;
		Graph[p][q]='#';
	}
	else
	{
		return ;
	}
    for(i=0;i<4;i++)
	{
		int x=p+direction[i][0];
		int y=q+direction[i][1];
		DFS(x,y);
	}
}

int main()
{
	int i,j,p,q;
	while(cin>>H>>W)
	{
		if(H==0 &&W ==0)
			break;
		for(i=0;i<W;i++)
		{
			for(j=0;j<H;j++)
			{
				cin>>Graph[i][j];
				if(Graph[i][j]=='@')
				{
					p=i;
					q=j;
					Graph[i][j]='.';
				}
			}
		}
		DFS(p,q);
		cout<<result<<endl;
	}
	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