
what??这是怎么肥四?
代码:
#include
using namespace std;
int v[110][110],xy[][2]={{1,0},{-1,0},{0,1},{0,-1}},n,m;
char a[110][110];
struct p{
int x,y,step;
}b,e,s;
queue
q;
int bfs(){
while (q.size()){
b=q.front();
for(int i=0;i<4;i++){
int xx=b.x+xy[i][0],yy=b.y+xy[i][1];
if(xx>=0 && xx=0 && yy'#'){
q.push({xx,yy,b.step+1});
if(xx==e.x && yy==e.y) return b.step+1;
v[xx][yy]=1;
}
}
q.pop();
}
return -1;
}
int main(){
cin>>n>>m;
for(int i=0;ifor(int j=0;j>a[i][j];
if(a[i][j]=='S') s.x=i,s.y=j,s.step=0,v[i][j]=1;
else if(a[i][j]=='T') e.x=i,e.y=j,e.step=0;
}
}
q.push(s);
cout>>bfs()>>"\n";
}