UVA 1343 - The Rotation Game
来源:互联网 发布:淘宝七乐康药店 假货 编辑:程序博客网 时间:2024/06/05 11:03
参考的刘汝佳大神的思路 IDA*算法 感觉用bfs会有超内存的危险==
#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;const int maxn = 25;const int id[10][10] = { {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} };const int cen[10] = {6, 7, 8, 11, 12, 15, 16, 17};const int rev[8] = {5, 4, 7, 6, 1, 0, 3, 2};char ans[10000];int str[maxn];int dep;bool judge(){ for(int i = 0; i < 8; ++i) if(str[cen[i]] != str[cen[0]]) return false; return true;}void move(int i) { int t = str[id[i][0]]; for(int j = 0; j < 6; j++) str[id[i][j]] = str[id[i][j+1]]; str[id[i][6]] = t;}int diff(int x) { int res = 0; for(int i = 0; i < 8; ++i) if(str[cen[i]] != x) ++res; return res;}int q() { return min(diff(1), min(diff(2), diff(3)));}bool dfs(int d) { if(judge()) { //cout << "++" << endl; ans[d] = '\0'; printf("%s\n", ans); return true; } if(d + q() > dep) return false; for(int i = 0; i < 8; ++i) { char t = 'A' + i; ans[d] = t; move(i); if(dfs(d+1)) return true; move(rev[i]); } return false;}int main(){ while(scanf("%d", &str[0]) != EOF && str[0]) { for(int i = 1; i < 24; ++i) scanf("%d", &str[i]); memset(ans, 0, sizeof(ans)); if(judge()) printf("No moves needed\n"); else { dep = 0; while(!dfs(0)) ++dep; } //printf("%d\n", dep);// for(int i = 0; i < 24; ++i) printf("%d ", str[i]);// printf("\n"); printf("%d\n", str[7]); } return 0;}
0 0
- UVa 1343 The Rotation Game
- UVA 1343 The Rotation Game
- UVA - 1343 The Rotation Game
- UVA 1343 - The Rotation Game
- uva 1343 The Rotation Game
- The Rotation Game UVA
- The Rotation Game (UVA
- The Rotation Game UVA
- The Rotation Game UVA
- UVa 1343:The Rotation Game(IDA*)
- UVA 1343(p210)----The Rotation Game
- UVa 1343 The Rotation Game(IDA*)
- UVA 1343 The Rotation Game 【IDA*】
- 1343 - The Rotation Game
- 1343 - The Rotation Game
- UVa #1343 The Rotation Game (例题7-12)
- POJ 2286 UVA 1343 The Rotation Game IDA*
- uva 1343 The Rotation Game_wrong
- 剑指offer整理归纳(1/2)
- HTML5 文件操作
- 从官网下载apache
- CCF-ISBN号码-201312-2
- Android自定义动画--卡牌翻牌动画
- UVA 1343 - The Rotation Game
- 主成分分析
- 面向对象
- 继承关系中的虚函数表
- Linux 磁盘管理
- c++primer之顺序容器(容器库概览)
- apache开启虚拟主机方法
- hdu2896-ac自动机
- [网络流24题] 21 最长k可重区间集(最大权不相交路径 ,最小费用最大流)