#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
struct node{
int x;
int y;
};
queue <node> Q;
int n,m;
int x1,y1;
int x2,y2;
int ans=0;
int a[505][505]={0};
bool b[505][505]={0};
inline void BFS()
{
int x3=0,y3=0;
while(!Q.empty())
{
x3=Q.front().x;
y3=Q.front().y;
b[x3][y3]=1;
Q.pop();
if(b[x3+1][y3]==0&&x3+1<=n&&a[x3+1][y3]==1)
{
if(x3+1==x2&&y3==y2)
{
ans++;
}
b[x3+1][y3]=1;
Q.push((node){x3+1,y3});
}
if(b[x3-1][y3]==0&&x3-1>0&&a[x3-1][y3]==1)
{
if(x3-1==x2&&y3==y2)
{
ans++;
}
b[x3-1][y3]=1;
Q.push((node){x3-1,y3});
}
if(b[x3][y3-1]==0&&y3-1>0&&a[x3][y3-1]==1)
{
if(x3==x2&&y3-1==y2)
{
ans++;
}
b[x3][y3-1]=1;
Q.push((node){x3,y3-1});
}
if(b[x3][y3+1]==0&&y3+1<=m&&a[x3][y3+1]==1)
{
if(x3==x2&&y3+1==y2)
{
ans++;
}
b[x3][y3+1]=1;
Q.push((node){x3,y3+1});
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for(register int i=1;i<=n;i++)
{
for(register int j=1;j<=m;j++)
{
char c;
cin>>c;
if(c=='g')
{
x2=i;
y2=j;
}
else if(c=='s')
{
x1=i;
y1=j;
}
else if(c=='#')
{
a[i][j]=0;
}
else if(c=='.')
{
a[i][j]=1;
}
}
}
Q.push((node){x1,y1});
BFS();
printf("%d",ans);
return 0;
}
为什么ans不会增加?