Problem Description

1 2 3 4
8 7 6 5

A: 上下两行互换,如上图可变换为状态87654321
B: 每行同时循环右移一格,如上图可变换为41236785
C: 中间4个方块顺时针旋转一格,如上图可变换为17245368

Input

Output

Sample Input
12345678 17245368 12345678 82754631

Sample Output
C AC

``` #include <stdio.h>
#include <string.h>
#include <queue>
#include <string>
#include <iostream>
using namespace std;
char st[],ed[];
int vis[];
string ans[];
int fac[] = {,,,,,,,,};
int getHash(char *str)//康托展开
{
int i,j,hash = ,cnt;
for(i=; i<; ++i)
{
cnt = ;
for(j=i+; j<; ++j)
if(str[j]<str[i])
cnt++;
hash += cnt * fac[-i-];
}
return hash;
}
struct node
{
char str[];
};
int d[][] = {{,,,,,,,},{,,,,,,,},{,,,,,,,}};
char change[];

void bfs()
{
queue<node> q;
node cur,tmp;
int i,j;
for(i=; i<; ++i)
cur.str[i] = i + '';
int hash = getHash(cur.str);
q.push(cur);
vis[hash] = true;
q.push(cur);
while(!q.empty())
{
cur = q.front(); q.pop();
int pHash = getHash(cur.str);
for(i=; i<; ++i)
{
for(j=; j<; ++j)
tmp.str[j] = cur.str[d[i][j]];
hash = getHash(tmp.str);
if(vis[hash]) continue;
vis[hash] = true;
ans[hash] = ans[pHash] + (char)('A' + i);
q.push(tmp);
}
}
}

int main()
{
bfs();
int i;
while(scanf("%s%s",st,ed)!=EOF)
{
for(i=; i<; ++i)
change[st[i]-''] =  i+'';//得到映射函数
for(i=; i<; ++i)
ed[i] = change[ed[i]-''];//根据映射函数改变目标状态
int hash = getHash(ed);
cout<<ans[hash]<<endl;
}
return ;
}```