Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
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: