解决了
scanf读进去了换行符,导致输入错误;
最开始的砖块没标记;
横纵坐标搞反了;
"park[next.x][next.y]=='#';"这句赋值打成"=="了
by inpac @ 2023-02-22 09:26:51
AC Code
```cpp
#include <iostream>
#include <cmath>
#include <string>
#include <queue>
#define maxn 25
using namespace std;
int w,h;
int fx,fy;
bool map[maxn][maxn];
bool visited[maxn][maxn];
int ans=0;
typedef pair<int,int> point;
int main()
{
cin>>w>>h;
string str;
for(int i=1;i<=h;++i)
{
cin>>str;
for(int j=1;j<=w;++j)
{
if(str[j-1]=='.')
map[i][j]=true;
else if(str[j-1]=='@')
{
fx=i; fy=j;
}
}
}
queue<point> q;
q.push(make_pair(fx,fy));
while(!q.empty())
{
point p=q.front();
q.pop();
int x=p.first, y=p.second;
if(visited[x][y]) continue;
visited[x][y]=true;
ans++;
if(x-1>=0 && !visited[x-1][y] && map[x-1][y]) q.push(make_pair(x-1,y));
if(y-1>=0 && !visited[x][y-1] && map[x][y-1]) q.push(make_pair(x,y-1));
if(y+1<=w && !visited[x][y+1] && map[x][y+1]) q.push(make_pair(x,y+1));
if(x+1<=h && !visited[x+1][y] && map[x+1][y]) q.push(make_pair(x+1,y));
}
cout<<ans<<endl;
return 0;
}
```
by jijidawang @ 2023-02-22 11:53:20
请勿抄袭,仅供参考
by jijidawang @ 2023-02-22 11:53:32