没输出
#include<iostream>//广度优先搜索
#include<queue>
using namespace std;
struct cow//牛牛结构体
{
int num;//步数
int x;//坐标
int y;
};
//变量和数组
int n, m, x, y;
int x2, y2;
int ax[4] = {0, 1, 0, 1};
int ay[4] = {1, 1, 0, 0};
char mg[400][400];//地图
bool flag[400][400];
bool tmp;
queue<cow> q;//牛牛
void search(int x1,int y1){
char ch = mg[x1][y1];
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
if(mg[i][j] == ch && i != x1 && j != y1){
x2 = i;
y2 = j;
}
}
}
}
int main(){
cin >> n >> m;
cow n1,n2;
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
cin >> mg[i][j];
if(mg[i][j] == '@'){
n1.x = i;
n1.y = j;
}
}
}
flag[x][y] = true;
n1.num = 0;
q.push(n1);//1 初始状态入队
//2 队列非空反复执行
while(!q.empty()){
n1 = q.front();//保留
//2-1 队头元素出队
q.pop();//出队
if(mg[n1.x][n1.y] == '='){
cout << n1.num << endl;
exit(0);
}
//2-2 拓展新状态,合法新状态入队
for(int i = 0;i < 4;i++){
tmp = false;
n2.x = n1.x + ax[i];
n2.y = n1.y + ay[i];
n2.num = n1.num + 1;
if(n2.x >= 0 && n2.x < n && n2.y >= 0 && n2.y < m && flag[n2.x][n2.y] == false){
for(char j ='A';j<='Z';j++){
if(mg[n2.x][n2.y] == j){
search(n2.x,n2.y);
tmp = true;
}
}
if(tmp){
flag[n2.x][n2.y] = true;
n2.x = x2;
n2.y = y2;
}
flag[n2.x][n2.y] = true;
q.push(n2);
}
}
}
return 0;
}