| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
暴搜0ms秒过!!!!附代码!!!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator