【IDA*(迭代加深)】PKU-2286||HUD-1667-The Rotation Game
来源:互联网 发布:十大网络作家 编辑:程序博客网 时间:2024/05/02 03:41
第一次写迭代加深,发觉这货很神气的说……虽然代码都是模仿人家的,不过自己加了一个判断条件,时间立刻减少一半……
某大牛对于IDA*的解析:所谓迭代加深,就是在深度无上限的情况下,先预估一个深度(尽量小)进行搜索,如果没有找到解,再逐步放大深度搜索。这种方法虽然会导致重复的遍历 某些结点,但是由于搜索的复杂度是呈指数级别增加的,所以对于下一层搜索,前面的工作可以忽略不计,因而不会导致时间上的亏空。
题目
#include<iostream>using namespace std;int dir[8][7]={{0,2,6,11,15,20,22},{1,3,8,12,17,21,23},{10,9,8,7,6,5,4},{19,18,17,16,15,14,13},{23,21,17,12,8,3,1},{22,20,15,11,6,2,0},{13,14,15,16,17,18,19},{4,5,6,7,8,9,10}};int h[8]={6,7,8,11,12,15,16,17};int re[8]={5,4,7,6,1,0,3,2};int l,p[24],ans[20];int check(){int i,d,b[5];for(i=1;i<4;i++)b[i]=0;for(i=0;i<8;i++)b[p[h[i]]]++;d=0;for(i=1;i<=3;i++)if(d<b[i])d=b[i];return 8-d;}void change(int x){int i,temp;temp=p[dir[x][0]];for(i=0;i<6;i++)p[dir[x][i]]=p[dir[x][i+1]];p[dir[x][i]]=temp;}int dfs(int d,int u){int i,temp;for(i=0;i<8;i++){if(u!=-1&&re[u]==i)continue; //这里判断是否和上一次的方向相反,如果相反就不进行下去了change(i);if((temp=check())==0){ans[d]=i;return 1;}if(d+temp<l) //只有在深度范围内才深搜下去{ans[d]=i;if(dfs(d+1,i))return 1;}change(re[i]);}return 0;}int main(){//freopen("a.txt","r",stdin);int i;while(scanf("%d",p)&&p[0]){for(i=1;i<24;i++)scanf("%d",p+i);if(check()==0){printf("No moves needed\n");printf("%d\n",p[6]);continue;}for(l=1;!dfs(0,-1);l++);for(i=0;i<l;i++)printf("%c",ans[i]+'A');printf("\n");printf("%d\n",p[6]);}return 0;}
- 【IDA*(迭代加深)】PKU-2286||HUD-1667-The Rotation Game
- POJ 2286 The Rotation Game 搜索-IDA*+迭代加深
- POJ 2286 HDU 1667 ZOJ 2396 The Rotation Game IDA*迭代加深搜索
- POJ 2286/HDU 1667 The Rotation Game 搜索-IDA*+迭代加深
- 迭代加深搜索IDA*---uva1343 the rotation game
- poj 2286 The Rotation Game (迭代加深搜索)
- POJ 2286 - The Rotation Game IDA(迭代加深搜索,DFSID)
- hdu 1667 /poj 2286 The Rotation Game(经典迭代加深)
- poj 2286 The Rotation Game 迭代加深搜索
- 【POJ2286】The Rotation Game-迭代加深DFS+可行性剪枝
- HDU-1667 The Rotation Game(IDA*)
- POJ - 2286 - The Rotation Game (IDA*)
- POJ 2286 The Rotation Game(IDA*)
- 2286 The Rotation Game (1,状压 2,迭代加深搜索)
- UVA1343(The rotation Game|旋转游戏)=》状态空间分析+迭代加深搜
- POJ 2286 The Rotation Game 迭代搜索深度 + A* == IDA*
- HDU 1667 The Rotation Game IDA*搜索
- 【IDA*】 HDOJ 1667 The Rotation Game
- 杭电 1034
- (第三周实验报告任务2)找错误
- 打造Windows环境下的GCC+VIM
- FPGA中inout端口使用方法总结
- POJ 3349 (hash)
- 【IDA*(迭代加深)】PKU-2286||HUD-1667-The Rotation Game
- online logo maker:在线制作具有专业水准的logo
- 第三周---类
- “分布式哈希”和“一致性哈希”的概念与算法实现
- hdu1058 Humble Number
- 10 条建议让你创建更好的 jQuery 插件
- 深入浅出学习struts1框架(五)--正式进入struts1框架学习,从一个实例开始
- Web 服务编程,REST 与 SOAP
- Oracle Spatial 组件 说明