再找不出错就要疯啦
结构体写的,样例都没过
哪位dalao帮我看看 T-T
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y,now;
};
char a[405][405];
bool b[405][405];
queue<node> q;
int n,m;
int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
int sx,sy;
void another(int tmpx,int tmpy,int k){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==a[tmpx][tmpy]&&(i!=tmpx||j!=tmpy)){
tmpx=i;
tmpy=j;
return;
}
}
}
}
void bfs(){
b[sx][sy]=1;
q.push((node){sx,sy,0});
while(!q.empty()){
node t=q.front();
q.pop();
if(a[t.x][t.y]=='='){
cout<<t.now;
return;
}
if(a[t.x][t.y]>='A'&&a[t.x][t.y]<='Z'){
another(t.x,t.y,t.now);
}
for(int j=0;j<=3;j++){
int gx=t.x+dx[j];
int gy=t.y+dy[j];
if(gx>=1&&gx<=n&&gy>=1&&gy<=m&&a[gx][gy]!='#'&&!b[gx][gy]){
b[gx][gy]=1;
q.push({gx,gy,t.now+1});
}
}
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]=='@'){
sx=i;
sy=j;
}
}
}
bfs();
return 0;
}
先谢谢了Orz Orz