UVA 1343 The Rotation Game 【IDA*】
来源:互联网 发布:博实股份人工智能 编辑:程序博客网 时间:2024/05/29 10:34
The Rotation Game
UVA - 1343#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<vector>#include<map>#include<set>#include<algorithm>using namespace std;#define ll long long#define ms(a,b) memset(a,b,sizeof(a))const int M=1e5+10;const int inf=0x3f3f3f3f;const int mod=1e9+7;int i,j,k,n,m;int a[30],maxd,path[100000];int roller[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 goalpos[8] = {6,7,8,11,12,15,16,17};int bac[8] = {5, 4, 7, 6, 1, 0, 3, 2};void rot(int *aa,int dir) { for(int i=1;i<7;i++) { int t = aa[roller[dir][i]]; aa[roller[dir][i]] = aa[roller[dir][i-1]]; aa[roller[dir][i-1]] = t; }}bool dfs(int d) { if(d == maxd) { for(int i=1;i<8;i++) { if(a[goalpos[i]] != a[goalpos[i-1]]) return false; } if(!d) { printf("No moves needed\n%d\n",a[6]); return true; } for(int i=0;i<d;i++) printf("%c",path[i]+'A'); printf("\n%d\n",a[6]); return true; } else { int res = 0; int a1 = 0 , b = 0 , c = 0 ; for(int i=0;i<8;i++) { if(a[goalpos[i]] == 1) ++a1; else if(a[goalpos[i]] == 2) ++b; else if(a[goalpos[i]] == 3) ++c; } res = 8 - max(a1,max(b,c)); if(d + res > maxd) return false; for(int i=0;i<8;i++) { path[d] = i; rot(a,i); if(dfs(d+1)) return true; rot(a,bac[i]); } } return false;}int main() { while(~scanf("%d",&a[0])&&a[0]) { for(int i=1;i<24;i++) scanf("%d",&a[i]); for(maxd = 0; ; ++maxd) { if(dfs(0)) break; } } return 0;}
阅读全文
0 0
- UVa 1343:The Rotation Game(IDA*)
- UVa 1343 The Rotation Game(IDA*)
- UVA 1343 The Rotation Game 【IDA*】
- POJ 2286 UVA 1343 The Rotation Game IDA*
- 1343 - The Rotation Game (IDA*算法)
- 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
- POJ2286 The Rotation Game IDA*
- [POJ2286]The Rotation Game IDA*
- 例题7-12 UVA - 1343 The Rotation Game 旋转游戏(IDA*)
- The Rotation Game UVA
- The Rotation Game (UVA
- The Rotation Game UVA
- The Rotation Game UVA
- UVA 1343(p210)----The Rotation Game
- 完全理解 Python 迭代对象、迭代器、生成器
- 关于如何实现 Object中的clone()方法
- linux 学习之查看进程
- CEF完整嵌入DUI窗体(三) --基本浏览器功能
- 欢迎使用CSDN-markdown编辑器
- UVA 1343 The Rotation Game 【IDA*】
- android_手势滑动+外形支援
- 初次见面python
- 判断字符串只有数字
- 2017.7.10 学习笔记 js基础
- Trie树
- jzoj3928【NOIP2014模拟11.6】射击(贪心)
- 动态申请权限
- poi.jar包学习笔记