准备用A*算法, 和 IDA*算法分别试一下。
A*算法
最好的A*算法 详解
摘自:https://www.redblobgames.com/pathfinding/a-star/introduction.html
国人翻译:https://www.cnblogs.com/L-Arikes/p/4314113.html
在摘录一篇
http://blog.csdn.net/hitwhylz/article/details/23089415
IDA*算法
分支定界其实是A*算法的雏形
迭代加深搜索(IDDFS )其实也是 ID A*的雏形
https://wenku.baidu.com/view/9dc0e27002768e9951e738d5.html
还没有写得完的华容道。
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MM=200001;
int chess[30][30];
int N,M,Q;
int dx={0,0,0,1,-1};
int dy={0,-1,1,0,0}
struct Node{
int d; //初始状态到此状态的距离
int h; //此状态到目标状态的距离
//int status; //棋盘状态 30行,30列,存不下啊!!
int X_space, Y_space; //当前空白位置。
int x, y; //当前在x。y位置。
bool operator <( Node b) const{ //原来这里必须加const
return ( d + h > b.d + b.h);
}
};
void request(int Ex,int Ey,int Sx,int Sy, int Tx, int Ty){
priority_queue< Node > que;
que.push( (Node){ 0, MM ,Ex, Ey, Sx, Sy} );
while( !que.empty()){
Node v = que.front(); que.pop();
for(int i=1;i<=4;i++){
int newx, newy;
newx += dx[i]; newy += dy[i];
//曼哈顿距离棋子偏离目标位置的水平距离和垂直距离和
if( ) que.push()
}
}
}
int main()
{
cin >> N >> M >> Q;
memset( chess, 0 , sizeof(chess));
for(int i=0;i<N;i++)
for(int j=0;j<M;j++){
int a; cin>>a;
//if(a==1) { S = S | (1<<(i*M+j) ;} //棋盘状态 30行,30列,存不下啊!!
chess[i][j] = a;
}
for(int i=1;i<=Q;i++){
int ex,ey,sx,sy,tx,ty;
cin>>ex>>ey>>sx>>sy>>tx>>ty;
request(ex,ey,sx,sy,tx,ty);
}
return 0;
}