資源簡介
重排九宮的廣度優(yōu)先算法 有代價(jià)函數(shù)實(shí)現(xiàn)局部優(yōu)先 用哈希表來看是否已經(jīng)在open表中
代碼片段和文件信息
#include?
#include?
#include?
using?namespace?std;
int?tgt[9]?=?{?0?};
int?hsTable[86419760]?=?{?0?};//搜索過為1
//節(jié)點(diǎn)類
class?Node
{
public:
int?state[9];
int?father;//父結(jié)點(diǎn)編號
int?difference;//與目標(biāo)的差異
int?depth;//深度
int?eva;//代價(jià)
int?loc;//在hsTable表位置
Node();
void?show();
void?setEva();
void?setState(int?a[9]);
void?setLoc();
};
Node::Node()
{
father?=?-1;
difference?=?9;
depth?=?0;
eva?=?INT_MAX;
int?i?temp?=?0;
for?(i?=?0;i?9;i++)
state[i]?=?i;
for?(i?=?0;i?8;i++)
{
temp?=?temp?*?10?+?state[i];
}
loc?=?temp?-?1234567;
}
void?Node::show()
{
for?(int?i?=?0;i?9;i++)
{
cout?< if?(i?==?2?||?i?==?5?||?i?==?8)
cout?< else
cout?<“?“;
}
}
void?Node::setEva(
評論
共有 條評論