uva 1343 The Rotation Game
来源:互联网 发布:iptables端口转发 编辑:程序博客网 时间:2024/05/29 18:52
题目:The Rotation Game
思路:IDA*。
注意:存储时可以就按题目中所给的形式。初始化时不能打错了。
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<map>#include<algorithm>#include<sstream>#include<queue>using namespace std;#define n 8#define m 24#define num 7int const Move[n+5][n+5]= {{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}};int const Central[n+5]= {0,7,8,9,12,13,16,17,18};int maxd=0;string Mstring;int b;int judge(int a[]) {int cnt[4]= {0};for(int i=1; i<=n; i++) {cnt[a[Central[i]]]++;}int Max=0,what;for(int i=1; i<=3; i++) {if(cnt[i]>Max) {Max=cnt[i],what=i;}}if(Max==8) return what;return 0-Max;}void DO(int (&c)[m+5],int x) {int t=c[Move[x][1]];for(int i=1; i<num; i++) {c[Move[x][i]]=c[Move[x][i+1]];}c[Move[x][num]]=t;}bool dfs(int d,int a[],string step) {if(d==maxd) {int x=judge(a);if(x<0) return false;b=x;Mstring=step;return true;}if(maxd<d+8+judge(a)) return false;for(int i=1; i<=n; i++) {int c[m+5];memcpy(c,a,sizeof(c));DO(c,i);if(dfs(d+1,c,step+(char)(i+'A'-1))) return true;}return false;}int main() {int a[m+5];while(~scanf("%d",&a[1])&&a[1]!=0) {for(int i=2; i<=m; i++) scanf("%d",&a[i]);int x=judge(a);if(x>0) {printf("No moves needed\n%d\n",x);continue;}maxd=0;while(++maxd) {if(dfs(0,a,"")) break;}cout<<Mstring<<endl;printf("%d\n",b);}return 0;}
阅读全文
3 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
- Makefile---(origin variable)详解
- 兼容写法获取元素样式
- Linux 下安装 Redis
- PHP-thinkPHP 路由
- 1022 数字图书馆
- uva 1343 The Rotation Game
- YTU.2683: 英文字母的判断
- Javaweb 开发相对与绝对路径的区别
- 常用小算法
- Linux-SHELL中sh和bash的区别
- UWP开发 Storyboard动画 2
- composer 小错误汇总(持续增加)
- JAVA 线程的几种状态
- 教学视频播放器(包含教学板书部分)