某本通1252,代码30分
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y,step;
};
char mp[50][50];
int mk[50][50],n,m;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
void bfs(int x,int y){
queue<node> q;
q.push((node){x,y,1});
mk[x][y]=1;
while(q.size()){
node t=q.front();
q.pop();
for(int i = 0;i < 4;i++){
int xx=t.x+dx[i];
int yy=t.y+dy[i];
if(xx==n&&yy==m){
cout << t.step+1;
return;
}
if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&!mk[xx][yy]&&mp[xx][yy]=='.'){
mk[xx][yy] = 1;
q.push((node){xx,yy,t.step+1});
}
}
}
}
int main() {
cin >> m >> n;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++) {
cin >> mp[i][j];
}
}
if(n==1 and m==1){
cout<<1;
return 0;
}
bfs(1,1);
return 0;
}