【POJ1077】Eight【IDA*】
来源:互联网 发布:ic卡读取软件 编辑:程序博客网 时间:2024/05/06 00:48
【题目链接】
学习一发IDA*。
/* Pigonometry */#include <cstdio>#include <iostream>using namespace std;const int maxn = 4, maxm = 105, inf = 0x3f3f3f3f;char opt[] = {'u', 'd', 'l', 'r'};int dx[] = {-1, 1, 0, 0};int dy[] = {0, 0, -1, 1};int mp[maxn][maxn], ed[maxn][maxn];bool found;char solu[maxm];inline int read() {char ch = getchar(); for(; !(ch == 'x' || (ch >= '0' && ch <= '9')); ch = getchar());return ch == 'x' ? 0 : ch - '0';}inline int intabs(int x) {return x < 0 ? -x : x;}inline int getH() {int res = 0;for(int i = 1; i <= 3; i++) for(int j = 1; j <= 3; j++) if(mp[i][j]) {int x = (mp[i][j] - 1) / 3 + 1, y = (mp[i][j] - 1) % 3 + 1;res += intabs(i - x) + intabs(j - y);}return res;}inline int dfs(int x, int y, int d, int lim) {int h = getH();if(h == 0 || found) {found = 1;return d;}if(d + h > lim) return d + h;int nowlim = inf;for(int i = 0; i < 4; i++) {int xx = x + dx[i], yy = y + dy[i];if(xx < 1 || xx > 3 || yy < 1 || yy > 3) continue;swap(mp[x][y], mp[xx][yy]);solu[d] = opt[i];int nextlim = dfs(xx, yy, d + 1, lim);nowlim = min(nowlim, nextlim);if(found) return nowlim;swap(mp[x][y], mp[xx][yy]);}return nowlim;}int main() {int sx, sy;for(int i = 1; i <= 3; i++) for(int j = 1; j <= 3; j++) {mp[i][j] = read();if(!mp[i][j]) sx = i, sy = j;ed[i][j] = (i - 1) * 3 + j;}ed[3][3] = 0;found = 0;int deplim = getH();while(deplim < 100 && !found) deplim = dfs(sx, sy, 0, deplim);if(!found) printf("unsolvable\n");else {solu[deplim] = '\0';printf("%s", solu);}return 0;}
0 0
- 【POJ1077】Eight【IDA*】
- 八数码 poj1077 Eight(A*、IDA*)
- POJ1077 Eight —— IDA*算法
- poj1077 Eight
- POJ1077&HDU1043 Eight 八数码第八境界 IDA* hash 康托展开 奇偶剪枝
- poj1077 /hdoj 1043 Eight
- POJ1077——Eight
- poj1077(A*,IDA*)
- Eight poj1077 广度优先搜索
- POJ 1077 Eight IDA*
- poj1077 hdu1043 Eight 八数码问题
- 【POJ1077】Eight-A*+康托展开
- poj1077 Eight —— 正向bfs+康拓
- POJ1077 Eight —— 正向BFS
- POJ1077 Eight —— 反向BFS
- POJ1077 Eight —— 双向BFS
- POJ1077 Eight —— A*算法
- 八数码与IDA*问题 HDU1043&&POJ1077
- uva11795 简单状态压缩DP
- 堆栈模拟队列
- c# 扩展方法详解
- [leetcode]Majority Element II
- Linux 下wifi 驱动开发(一)—— WiFi基础知识解析
- 【POJ1077】Eight【IDA*】
- 自定义一个文字居左图片居右的按钮
- xml不能里面的上下间隔问题 ,如果存在需要隐藏的项的时候 ,最好是在隐藏项加layout_marginBottom,而不用在下面那项加top
- 最小二乘法拟合直线
- lightoj 1017 - Brush (III)(dp)
- jsp的include两种使用方法
- android fragment生命周期
- 2——Building Microservices: Using an API Gateway
- JVM(1)--java内存模型