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

暴搜0ms秒过!!!!附代码!!!

Posted by wocha at 2012-04-25 16:55:25 on Problem 1562
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 char map[333][333];
void Dfs(int x,int y)
{
	  map[x][y]='*';
	  if(map[x-1][y]=='@')
		Dfs(x-1,y);
		if(map[x-1][y+1]=='@')
		Dfs(x-1,y+1);
		if(map[x][y+1]=='@')
		Dfs(x,y+1);
		if(map[x+1][y+1]=='@')
		Dfs(x+1,y+1);
		if(map[x+1][y]=='@')
		Dfs(x+1,y);
		if(map[x+1][y-1]=='@')
		Dfs(x+1,y-1);
		if(map[x][y-1]=='@')
		Dfs(x,y-1);
    if(map[x-1][y-1]=='@')
		Dfs(x-1,y-1);
	//	 map[x][y]='@';
		return ;

}
int main()
{
	int N,M,i,j,n,m,l,q,w,e;
	while(~scanf("%d%d\n",&N,&M),N,M){
	 //getchar();

	 memset(map,'*',sizeof(map));
	 for(i=1;i<=N;i++)
		{
			for(j=1;j<=M;j++)
			 map[i][j]=getchar();
			if(i!=N) getchar();
		}
		int cnt=0;
		for(i=1;i<=N;i++)
		 {
				for(j=1;j<=M;j++)
					if(map[i][j]=='@')
					{
		 cnt++;
		 Dfs(i,j);
					}

			}
			printf("%d\n",cnt);
	// getchar(); getchar(); getchar();
}
		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