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 laijiayi at 2013-08-17 15:04:52 on Problem 1562
In Reply To:跪求求大神指导!测了多数据了,都过了,为啥WA ?????? Posted by:bj921712230 at 2013-04-21 20:31:42
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define M 101
using namespace std;
bool visit[M][M];
int xx[8]={1,1,1,-1,-1,-1,0,0};
int yy[8]={1,0,-1,1,0,-1,1,-1};
char point[M][M];
int m,n;
void DFS(int x,int y)
{
	visit[x][y]=true;
	for(int i=0;i<8;i++)
	{
		if(x+xx[i]>=0&&x+xx[i]<m&&y+yy[i]>=0&&y+yy[i]<n)
		{
			if(point[x+xx[i]][y+yy[i]]=='@'&&visit[x+xx[i]][y+yy[i]]==0)
			{
				DFS(x+xx[i],y+yy[i]);
			}
		}
	}
}
int main()
{
	int b,i,j,k,T;
	while(scanf("%d %d",&m,&n)!=EOF&&m)
	{
		memset(visit,0,sizeof(visit));
		k=0;
		for(i=0;i<m;i++)
		{
			getchar();
			for(j=0;j<n;j++)
			{
				scanf("%c",&point[i][j]);
			}
		}
		for(i=0;i<m;i++)
		{
			for(j=0;j<n;j++)
			{
				if(point[i][j]=='@'&&visit[i][j]==0)
				{
					k++;
					DFS(i,j);
				}
			}
		}
		printf("%d\n",k);
	}
	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