电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

八数码C语言A算法详细代码

八数码C语言A算法详细代码_第1页
1/7
八数码C语言A算法详细代码_第2页
2/7
八数码C语言A算法详细代码_第3页
3/7
#include#include#include#include#includeusing namespace std;struct node{int a[3][3]; //存放矩阵int father; //父节点得位置 int gone; //就是否遍历过,1为就是,0为否int fn; //评价函数得值int x,y; //空格得坐标int deep; //节点深度 };vector store; //存放路径节点int mx[4]={1,0,1,0};int my[4]={0,1,0,1}; //上下左右移动数组int top; //当前节点在store中得位置bool check(int num) //推断store[num]节点与目标节点就是否相同,目标节点储存在store[0]中 {for(int i=0;i<3;i++){for(int j=0;j<3;j++){if(store[num]、a[i][j]!=store[0]、a[i][j])return false;}}return true;} bool search(int num) //推断store[num]节点就是否已经扩展过 ,没有扩展返回true {int pre=store[num]、father; //pre指向store[num]得父节点位置 bool test=true;while(!pre){ //循环直到pre为0,既初始节点 for(int i=0;i<3;i++){for (int j=0;j<3;j++){if(store[pre]、a[i][j]!=store[num]、a[i][j]){test=false;break;}}if(test==false) break;}if(test==true) return false;pre=store[pre]、father; //pre继续指向store[pre]父节点位置 }return true;}void print(int num) //打印路径,store[num]为目标节点 {vector temp; //存放路径 int pre=store[num]、father;temp、push_back(num);while(pre!=0){ //从目标节点回溯到初始节点 temp、push_back(pre);pre=store[pre]、father;}cout<=0;m){cout<<"第"<

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

八数码C语言A算法详细代码

确认删除?
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群