UVA-6.4.1-油田-572-DFS
题目描述:
和刚刚做的一道题差不多:http://blog.csdn.net/qq_36624681/article/details/54411182
此题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=838&problem=513&mosmsg=Submission+received+with+ID+18615842
题目分析:
不想分析=。=
给出代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void com(char num[110][110],int x,int y,int a,int b);
int count=0;
int main()
{
char num[110][110];
memset(num,0,sizeof(num));
int x,y;
while(scanf("%d%d",&x,&y)!=EOF&&x&&y)
{
char space;
space=getchar();
int i,j;
for(i=1; i<=x; i++)
{
for(j=1; j<=y; j++)
{
scanf("%c",&num[i][j]);
}
space=getchar();
}
for(i=1; i<=x; i++)
{
for(j=1; j<=y; j++)
{
if(num[i][j]=='@')
{
count++;
com(num,x,y,i,j);
i=1;
j=1;
}
}
}
printf("%d\n",count);
count=0;
memset(num,0,sizeof(num));
}
return 0;
}
void com(char num[110][110],int x,int y,int a,int b)
{
//printf("%d %d\n",a,b);
//printf("%c\n",num[a][b]);
if(num[a][b]=='*')
{
//printf("PRZ\n");
return;
}
if(num[a][b]=='@')
{
num[a][b]='*';
int i,j;
for(i=-1; i<=1; i++)
{
for(j=-1; j<=1; j++)
{
int a1=a+i;
int b1=b+j;
//printf("**%d %d\n",a1,b1);
if(a1>0&&a1<=x&&b1>0&&b1<=y)
{
//printf("ORZ\n");
com(num,x,y,a1,b1);
//printf("ORZ\n");
}
}
}
return;
}
return;
}