1.题目
输入样例
8 2
########
#S@@@@@#
#@####@#
#@####@#
#@####@#
#@####@#
#b@G@@a#
########
输出样例
19
(最优路径:S→a→G→b→G)
2.分析
- 结构体:
struct point{
int x;
int y;//位置
int step=0;//S到该位置的距离
char ch='a';//准备遇到的宝箱
point(){
}
point(int _x,int _y,int s=0,char _ch='a'){
x=_x;y=_y;step=s;ch=_ch;}
};
2.算法:BFS
优先队列顶储存step最小的point
visited[N][N]已访问列表每当遇见该遇见的宝箱,清零
3.AC代码
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int N,K;
struct point{
int x;
int y;
int step=0;
char ch='a';
point(){
}
point(int _x,int _y,int s=0,char _ch='a'){
x=_x;y=_y;step=s;ch=_ch;}
<