1 条题解
-
0赵青海 (huhe) LV 7 SU @ 2022-7-25 16:39:11
#include<bits/stdc++.h> using namespace std; int depth; int op[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} }; int w[100]; int ways[10]= {6,7,8,11,12,15,16,17}; int f() { int st[5]= {}; for(int i = 0; i<8; i++) { st[w[ways[i]]]++; } int maxn = 0; for(int i = 1; i<=3; i++) { if(st[i]>maxn) { maxn = st[i]; } } return 8-maxn; } int abop[10]= {5,4,7,6,1,0,3,2}; int path[100]= {}; void operate(int x) { int t = w[op[x][0]]; for(int i = 0; i<6; i++) { w[op[x][i]] = w[op[x][i+1]]; } w[op[x][6]] = t; } int dfs(int step,int last) { if(step+f()>depth) return 0; if(f() == 0) return 1; for(int i = 0; i<8; i++) { if(abop[i]!=last) { operate(i); path[step] = i; if(dfs(step+1,i)) return 1; operate(abop[i]); } } return 0; } int main() { while(cin>>w[0],w[0]) { for(int i = 1; i<=23; i++) cin>>w[i]; depth = 0; while(!dfs(0,-1)) depth++; if(!depth) cout<<"No moves needed"<<endl<<w[6]<<endl; else { for(int i = 0; i<depth; i++) cout<<char(path[i]+'A'); cout<<endl<<w[6]<<endl; } } return 0; }
- 1
信息
- ID
- 92
- 时间
- 3000ms
- 内存
- 128MiB
- 难度
- 3
- 标签
- 递交数
- 80
- 已通过
- 43
- 上传者