
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<memory.h> 5 #include<string> 6 #define INF 0x3f3f3f3f 7 using namespace std; 8 9 const int indexs[8][7]= 10 { 11 {0,2,6,11,15,20,22}, 12 {1,3,8,12,17,21,23}, 13 {10,9,8,7,6,5,4}, 14 {19,18,17,16,15,14,13}, 15 {23,21,17,12,8,3,1}, 16 {22,20,15,11,6,2,0}, 17 {13,14,15,16,17,18,19}, 18 {4,5,6,7,8,9,10}, 19 }; 20 const int ni[]={5,4,7,6,1,0,3,2,-1}; 21 const int center[]={6,7,8,11,12,15,16,17}; 22 int min(int a,int b) {return a>b ? b : a;} 23 int max(int a,int b) {return a<b ? b : a;} 24 char map[24]; 25 char route[101]; 26 bool hasSolution; 27 28 void pull(int op) 29 { 30 int temp=map[indexs[op][0]]; 31 for (int i=0;i<7-1;i++) 32 { 33 map[indexs[op][i]]=map[indexs[op][i+1]]; 34 } 35 map[indexs[op][6]]=temp; 36 } 37 38 int h() 39 { 40 int cnt[3]={0,0,0}; 41 int maxCnt= -1; 42 for(int i=0;i<8;i++) 43 { 44 cnt[map[center[i]]-1]++; 45 maxCnt=max(maxCnt,cnt[map[center[i]]-1]);//作用和if.m>cnt.m=cnt[]一样; 46 } 47 return 8-maxCnt; 48 } 49 50 void dfs(int depth,int lastop,int maxdepth ) 51 { 52 if(hasSolution) return ; 53 if(h()==0) 54 { 55 hasSolution=true; 56 route[depth]='