POJ2286 The Rotation Game
来源:互联网 发布:怎样成为淘宝客服 编辑:程序博客网 时间:2024/05/22 09:42
题目:http://poj.org/problem?id=2286
分析:第一个IDA* 程序。。WA了无数次,原因:判深度超应该放在判合法解之前!
代码:
#include <cstdio>#include <algorithm>#include <cstring>#include <vector>using namespace std;const int Tmax=30,p[9][8]={{0},{0,1,3,7,12,16,21,23},{0,2,4,9,13,18,22,24},{0,11,10,9,8,7,6,5},{0,20,19,18,17,16,15,14},{0,24,22,18,13,9,4,2},{0,23,21,16,12,7,3,1},{0,14,15,16,17,18,19,20},{0,5,6,7,8,9,10,11}};const int cp[9]={0,7,8,9,12,13,16,17,18};int a[Tmax],dep,num[4],z[Tmax]={0,1,1,1,1,3,2,3,2,3,1,3,2,2,3,1,2,2,2,3,1,2,1,3,3};vector<int> ans;bool ok(){ int i; for(i=2;i<=8;i++) if(a[cp[i]]!=a[cp[1]]) return false; return true;}int h(){ int i; num[1]=num[2]=num[3]=0; for(i=1;i<=8;i++) num[a[cp[i]]]++; return max(num[1],max(num[2],num[3]));}bool dfs(int d,int pre){ if(d>dep) return false; if(ok()) return true; if(d+8-h()>dep+1) return false; int i,tmp,j; for(i=1;i<=8;i++) { if((i==1&&pre==6)||(i==2&&pre==5)||(i==3&&pre==8)||(i==4&&pre==7)||(i==5&&pre==2)||(i==6&&pre==1)||(i==7&&pre==4)||(i==8&&pre==3)) continue; tmp=a[p[i][1]]; for(j=1;j<=6;j++) a[p[i][j]]=a[p[i][j+1]]; a[p[i][7]]=tmp; ans.push_back(i); if(dfs(d+1,i)) return true; ans.pop_back(); tmp=a[p[i][7]]; for(j=7;j>=2;j--) a[p[i][j]]=a[p[i][j-1]]; a[p[i][1]]=tmp; } return false;}int main(){ int i; while(scanf("%d",&a[1])&&a[1]!=0) { ans.clear(); for(i=2;i<=24;i++) scanf("%d",&a[i]); if(ok()) { printf("No moves needed\n"); printf("%d\n",a[7]); continue; } dep=1; while(!dfs(0,-10)) dep++; for(i=0;i<ans.size();i++) printf("%c",ans[i]+'A'-1); printf("\n%d\n",a[7]); } return 0;}
0 0
- POJ2286 The Rotation Game
- 【POJ2286】The Rotation Game
- POJ2286 - The Rotation Game
- POJ2286 The Rotation Game IDA*
- [POJ2286]The Rotation Game IDA*
- POJ2286 The Rotation Game(IDA*)
- 【POJ2286】The Rotation Game-迭代加深DFS+可行性剪枝
- 【C++心路历程34】【HDU1667】【POJ2286】【UVA1343紫书210例题】the rotation game
- 1343 - The Rotation Game
- UVa1343 - The Rotation Game
- 1343 - The Rotation Game
- BZOJ1327: The Rotation Game
- The Rotation Game uva1343
- bzoj1327: The Rotation Game
- The Rotation Game UVA
- The Rotation Game (UVA
- The Rotation Game UVA
- The Rotation Game UVA
- WPF 中通过ComBox的改变来改变Frame中的子.xaml项 View-ViewModel模式
- vim取消语法高亮
- c语言的隐式转换
- mysql常用操作
- 常量传递1
- POJ2286 The Rotation Game
- 苹果再下一盘很大的棋?Metal优化作用及影响浅析
- poj 1661 Help Jimmy
- android 每周学习笔记及总结(每周更新)
- hdu1312 Red and Black(搜索基础)
- RecyclerView
- hdu 1015 Safecracker 暴力
- POSIX 下进程控制经典案例
- 变量与环境变量