大致就是一个人能踩黑地板不能踩红地板,问最多有多少地板能踩
典型的简单搜索题,然后我卡了两个小时发现赋值语句我多写了个等号...mmp
代码调试能力太差了,错误都看不出来...
做个转换然后然后...没了
#include<stdio.h>
#include<string.h>
int b[21][21]={0};
int a[21][21]={0};
int w,h;
void dfs(int x,int y)
{
b[x][y]=1;
if (x-1>=1) if (a[x-1][y]==1&&b[x-1][y]==0) dfs(x-1,y);
if (x+1<=h) if (a[x+1][y]==1&&b[x+1][y]==0) dfs(x+1,y);
if (y-1>=1) if (a[x][y-1]==1&&b[x][y-1]==0) dfs(x,y-1);
if (y+1<=w) if (a[x][y+1]==1&&b[x][y+1]==0) dfs(x,y+1);
}
int main()
{
scanf("%d%d",&w,&h);
while (1)
{
int i,j,c=0,ri,rj;
char t[21]="";
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
if (w==0&&h==0) break;
for (i=1;i<=h;i++)
{
scanf("%s",t);
for (j=0;j<=w-1;j++)
{
if (t[j]=='.') a[i][j+1]=1;
if (t[j]=='#') a[i][j+1]=0;
if (t[j]=='@') {a[i][j+1]=1;ri=i;rj=j+1;}
}
}
dfs(ri,rj);
for (i=1;i<=h;i++)
for (j=1;j<=w;j++)
if (b[i][j]==1) c++;
printf("%d\n",c);
scanf("%d%d",&w,&h);
if (w==0&&h==0) break;
}
}