设为首页 加入收藏

TOP

POJ-3131-Cubic Eight-Puzzle(双向BFS+哈希)(二)
2015-07-24 05:42:02 来源: 作者: 【 】 浏览:14
Tags:POJ-3131-Cubic Eight-Puzzle 双向 BFS 哈希
t]=0; stk.push(getstate()); mp[cnt]=old; mp[cnt-1]=0; } cnt-=1; cnt-=1; if(cnt>=0 && cnt<9 && cnt%3<2) { old=mp[cnt]; mp[cnt+1]=nxt[0][mp[cnt]]; mp[cnt]=0; stk.push(getstate()); mp[cnt]=old; mp[cnt+1]=0; } cnt+=1; cnt-=3; if(cnt>=0 && cnt<9) { old=mp[cnt]; mp[cnt+3]=nxt[1][mp[cnt]]; mp[cnt]=0; stk.push(getstate()); mp[cnt]=old; mp[cnt+3]=0; } cnt+=3; cnt+=3; if(cnt>=0 && cnt<9) { old=mp[cnt]; mp[cnt-3]=nxt[1][mp[cnt]]; mp[cnt]=0; stk.push(getstate()); mp[cnt]=old; mp[cnt-3]=0; } cnt-=3; } int bfs() { int step1=0,step2=0,ans=INF,temp; for(step1=0;step1<=20;step1++) { while(top1 =0;i--) { if(i!=x*3+y) temp=temp*7+1; else temp*=7; } if(vis2[hashval(temp)]) { printf("0\n"); continue; } vis1[hashval(temp)]=1; que1[bottom1].step=0; que1[bottom1].state=temp; bottom1++; printf("%d\n",bfs()); } }

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Effective C++:条款38:通过复合.. 下一篇HexDump.java解析

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: