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

why WA???????dfs??

Posted by sailors at 2007-04-19 21:38:38 on Problem 2386
#include<memory.h>
#include<string.h>
//#include<iostream.h>

#include<stdio.h>
char a[101][101];
int pass[101][101];
int vetor[8][2]={{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1}};
int N,M;

int search(int x,int y)
{
	int h,g;
//	a[x][y]='.';
	pass[x][y]=1;
	for(int i=0;i<8;i++)
	{
		h=x+vetor[i][0];
		g=y+vetor[i][1];
		if(h>=0&&h<=N-1&&g>=0&&g<=M-1)
		{
			if(a[h][g]=='W'&&pass[h][g]==0)
			{
				pass[g][h]=1;
				//	a[h][g]='.';
				search(h,g);

			}
		}
	}
	return 0;
}

int main()
{
	int i,j;
	while(scanf("%d%d",&N,&M)!=EOF)
	{
		//cin.get();
		//printf("%d  %d\n",N,M);
		for(i=0;i<N; i++)
		{
			//for( j=0;j<M;j++)
			{
				scanf("%s",&a[i]);	///cin>>a[i][j];
			}
		}
		memset(pass,0,sizeof(pass));

		int cnt=0;

		for(i=0;i<N;i++)
		{
			for(j=0;j<M;j++)
			{
				if(pass[i][j]==0&&a[i][j]=='W')
				{
				//	pass[i][j]=1;
					cnt++;
				   search(i,j);
				   
				}
			}
		}
		printf("%d\n",cnt);
	}


	return 0;
}
/*

10 12
W........WW.
.WWW.....WWW
....WW...WW.
.........WW.
.........W..
..W......W..
.W.W.....WW.
W.W.W.....W.
.W.W......W.
..W.......W.


*/

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