代码:
#include <bits/stdc++.h>
using namespace std;
struct point{
int x,y,s;
//bool bo;//是否有被走过(0:没走过 1:走过)
};
struct ma{
int x1,y1,x2,y2;
}a[100];
char b[305][305];
int main(){
int n,m;
cin>>n>>m;
queue<point> q;
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
cin>>b[i][j];
if(b[i][j]>='A' && b[i][j]<='Z'){
if(a[b[i][j]].x1 == 0) a[b[i][j]].x1=i,a[b[i][j]].y1=j;
else a[b[i][j]].x2=i,a[b[i][j]].y2=j;
}
if(b[i][j] == '@') q.push(point{i,j,0});
}
}
int dx[5]={0,0,0,-1,1},dy[5]={0,-1,1,0,0};
//BFS
while(!q.empty()){
point p=q.front();
q.pop();
for(int i=1;i<=4;i++){
int xx= p.x+dx[i], yy= p.y+dy[i];
if(xx<1 || xx>m || yy<1 || yy>n) continue;
// || p.bo==1
if(b[xx][yy] == '#') continue;
int step = p.s+1;
if(b[xx][yy] == '='){
cout<<step;
return 0;
}
if(b[xx][yy]>='A' && b[xx][yy]<='Z'){
if(a[b[xx][yy]].x1 == xx){
q.push( point{a[b[xx][yy]].x2, a[b[xx][yy]].y2, step} );
}else{
q.push( point{a[b[xx][yy]].x1, a[b[xx][yy]].y1, step} );
}
}
q.push(point{xx,yy,step});
}
}
return 0;
}
结果输出总是错误,0分
请大佬们帮我调一下代码