hdu2612 Find a way Y和M要去KFC见面,地图上有很多个KFC,求两个人去最近的KFC所走距离的和,KFC也是可以走的 题解:数据不大,BFS直接搜出两个人走到每个点的距离保存下来,最后计算去每个KFC所走距离和最小值即可,具体看代码 #include <iostream> #include <cstring> #include <queue> using namespace std; const int maxn=500; char pic[maxn][maxn]; int vis[maxn][maxn]; //标记走过的路 int step1[maxn][maxn]; int step2[maxn][maxn]; //每个人去每个点的步数 int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0};//dx和dy代表上下左右四个方向 int n,m; struct node { int x,y; }; void bfs(int sx,int sy,int step[][500]) { queue<node>Q; node now; now.x=sx; now.y=sy; step[now.x][now.y]=0; Q.push(now); while(!Q.empty()) { now=Q.front(); Q.pop(); node next; for(int i=0;i<4;i++) //上下左右四个方向 { next.x=now.x+dx[i]; next.y=now.y+dy[i]; if(!vis[next.x][next.y]&&pic[next.x][next.y]!='#&#