题目描述
Input
Output
Sample Input
4 4
Y.#@
…
.#…
@…M
4 4
Y.#@
…
.#…
@#.M
5 5
Y…@.
.#…
.#…
@…M.
#…#
Sample Output
66
88
66
//////////////////////////////////////////////////////////////////////////////////////////////////
题意:一张二维地图,两人从不同起点出发去恰KFC。
“Y M”二人出发位置
“#"障碍
"@"KFC位置
"."可走道路
找到最短路径和
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int N = 205;
char a[N][N];//存储地图
char f1[N][N];//标记Y走过的位置
char f2[N][N];//标记M走过的位置
int d1[N][N];//点到Y的距离
int d2[N][N];//点到M的距离
int n,m;// 地图长宽
struct node
{
int x,y;
};
void bfs_1(int x,int y)//从Y开始广搜
{
queue<node>q;
q.push({
x,y});
while(!q.empty())
{
node st=q.front();
q.pop();
f1[st.x][st.y]