#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <queue> #define x first #define y second using namespace std; // pair 有两个属性,first 和 second ,建议宏定义为x和y,方便理解 typedef pair
#include <iostream> #include <cstring> #include <algorithm> #include <queue> #include<unordered_map> using namespace std; //状态转移 int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; int bfs(string strat) { //定义目标状态、 string end = "12345678x"; //定义队列和dis...
#include<vector> #include<algorithm> #include<queue> #include<unordered_set> usingnamespacestd; #defineSTATIONNUMS 14//地铁站的数量 intsstation =1;//起始站的位置 intestation =11;//终点站位置 structedge{//路线 intstartSta;//起始站点编号 intendSta;//下一站站点编号 edge(intsS,inteS) :start...
只不过在实现方式上不同(广度优先或深度优先)queue <--- 初始状态 // 队列保存初始状态 while(queue ...
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>#define x first #define y second using namespace std;// pair 有两个属性,first 和 second ,建议宏定义为x和y,方便理解typedef pair<int,int>PII;constintN=210;int n,m;// 存储地图char g[N][N];// 存储坐...
#include<algorithm> using namespace std; int R, C; //行数和列数 int color[60][60]; //用来标记当前房间是否访问过 int room[60][60]; int maxRoomArea = 0; //用来记录面积最大的房间 int roomNumber = 0; //房间数量 int roomArea; //用来记录房间的面积 ...
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>#definex first#definey secondusingnamespacestd;// pair 有两个属性,first 和 second ,建议宏定义为x和y,方便理解typedefpair<int,int> PII;constintN =210;intn, m;// 存储地图charg[N][N];// 存储坐标intdist[...
#include<iostream> #include<queue> #include<algorithm> using namespace std; typedef pair<int, int> pii; #define x first //这样子代码会比较短 #define y second const int N = 25; char g[N][N]; //存地图 int st[N][N]; int m, n; //m是列, n是行 int bfs(int sx, int sy) ...
使用普通的队列和优先队列相比,优先队列能更快地找到目的变量。 #include<iostream> #include<string> #include<cstring> #include<iomanip> #include<stack> #include<queue> #include #include<vector> #include<algorithm> #include<cmath> using namespace std; # define...
*/#include<iostream>#include<algorithm>#include<unordered_map>#include<queue>usingnamespacestd;intbfs(string state){queue<string> q;//用字符串来标记变换次数,字符串做下标unordered_map<string,int> d;q.push(state);//初始化移动次数d[state]=0;//四个方向intdx[4]={-1,0,1,...