The Rotation Game uva1343
来源:互联网 发布:时尚杂志知乎 编辑:程序博客网 时间:2024/06/07 05:17
#include <stdio.h>#include <iostream>#include <algorithm>#include <stack>#include <string>#include <string.h>using namespace std;#define N 10int n;int mat[N][N];int pos=0;int ans[100];bool read(){ if(cin>>mat[1][3]&&mat[1][3]) { cin>>mat[1][5]; cin>>mat[2][3]; cin>>mat[2][5]; for(int i=1;i<=7;i++) cin>>mat[3][i]; cin>>mat[4][3]>>mat[4][5]; for(int i=1;i<=7;i++) cin>>mat[5][i]; cin>>mat[6][3]>>mat[6][5]; cin>>mat[7][3]>>mat[7][5]; return 1; } return 0;}void aopr(){ int buff=mat[1][3]; for(int i=1;i<=6;i++) mat[i][3]=mat[i+1][3]; mat[7][3]=buff;}void bopr(){ int buff=mat[1][5]; for(int i=1;i<=6;i++) mat[i][5]=mat[i+1][5]; mat[7][5]=buff;}void copr(){ int buff=mat[3][7]; for(int i=7;i>=2;i--) mat[3][i]=mat[3][i-1]; mat[3][1]=buff;}void dopr(){ int buff=mat[5][7]; for(int i=7;i>=2;i--) mat[5][i]=mat[5][i-1]; mat[5][1]=buff;}void eopr(){ int buff=mat[7][5]; for(int i=7;i>=2;i--) mat[i][5]=mat[i-1][5]; mat[1][5]=buff;}void fopr(){ int buff=mat[7][3]; for(int i=7;i>=2;i--) mat[i][3]=mat[i-1][3]; mat[1][3]=buff;}void gopr(){ int buff=mat[5][1]; for(int i=1;i<=6;i++) mat[5][i]=mat[5][i+1]; mat[5][7]=buff;}void hopr(){ int buff=mat[3][1]; for(int i=1;i<=6;i++) mat[3][i]=mat[3][i+1]; mat[3][7]=buff;}void opr(int op){ if(op==1) aopr(); else if(op==2) bopr(); else if(op==3) copr(); else if(op==4) dopr(); else if(op==5) eopr(); else if(op==6) fopr(); else if(op==7) gopr(); else hopr();}void rop(int op){ if(op==1) fopr(); else if(op==2) eopr(); else if(op==3) hopr(); else if(op==4) gopr(); else if(op==5) bopr(); else if(op==6) aopr(); else if(op==7) dopr(); else if(op==8) copr();}int find(){ int num[5];for(int i=1;i<=3;i++) num[i]=0; for(int i=3;i<=5;i++) ++num[mat[3][i]]; num[mat[4][3]]++; num[mat[4][5]]++; for(int i=3;i<=5;i++) ++num[mat[5][i]]; return max(max(num[1],num[2]),num[3]);}void dfs(int now,int depth){ if(pos) return; int buff=find(); //cout<<now<<' ' <<buff<<' '<<depth<<endl; if(now+8-buff>depth) return; if(now>depth) return;//顶多差一层 if(buff==8) { if(now==0) {printf("No moves needed\n");printf("%d\n",mat[3][3]);pos=1;} else { for(int i=0;i<depth;i++) printf("%c",ans[i]+'A'-1); printf("\n%d\n",mat[3][3]); pos=1; } return; } for(int i=1;i<=8;i++) {if(pos) return ;opr(i);ans[now]=i;dfs(now+1,depth);rop(i);}}void init(){ pos=0; memset(mat,0,sizeof(mat)); // memset(num,0,sizeof(num));}void solve(){ int depth; for(depth=0;;depth++) { dfs(0,depth); if(pos) break; }}int main(){ while(read()) { solve(); init(); } /*read(); int op; while(cin>>op) { opr(op); for(int i=1;i<=7;i++) { for(int j=1;j<=7;j++) cout<<mat[i][j]<<' '; cout<<endl; } }*/ return 0;}很简单的ida* 这个剪枝只要一个就好了! 就是 now+ 8 - find()> depth 就好了
0 0
- UVa1343 - The Rotation Game
- The Rotation Game uva1343
- uva1343(The Rotation Game)=>IDA*
- Uva1343 The Rotation Game 【IDA*】【例题7-12】
- 迭代加深搜索IDA*---uva1343 the rotation game
- UVA1343(The rotation Game|旋转游戏)=》状态空间分析+迭代加深搜
- 【C++心路历程34】【HDU1667】【POJ2286】【UVA1343紫书210例题】the rotation game
- 例题7-12 旋转游戏(The Rotation Game, Shanghai 2004, UVa1343)
- 1343 - The Rotation Game
- 1343 - The Rotation Game
- POJ2286 The Rotation Game
- 【POJ2286】The Rotation Game
- BZOJ1327: The Rotation Game
- POJ2286 - The Rotation Game
- bzoj1327: The Rotation Game
- The Rotation Game UVA
- The Rotation Game (UVA
- The Rotation Game UVA
- 欢迎使用CSDN-markdown编辑器
- 【SQL】一条查询中统计同一字段不同记录值数量(频数统计)的写法
- 【验证码一】验证码Demo
- 关于函数传参问题自己的看法
- 百度指数抓取-趋势截图+估算方法
- The Rotation Game uva1343
- word2vec 中的数学原理详解
- [LeetCode]230. Kth Smallest Element in a BST
- 腾讯云服务器win2008系统搭建VPN
- LNK2038 RuntimeLibrary 不匹配的解决
- C#中不同格式数据校验的正则表达式
- 算法导论第八章思考题-c++
- 【验证码二】使用验证码
- CC150 3.4 Queue via Stacks