搜索题,

每个状态能扩展出12种状态,最多进行5次旋转12^5

要用到iddfs,或者我看到网上其他人用的ida*

我也是参考了别人的代码,而且这个题vj上有点问题,我看数据看了半天,愣是没看明白第二个数据咋回事,后来才知道是vj显示的有问题

#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<string>
using namespace std;
#define ll long long
#define se second
#define fi first
#define oo 0x3fffffff
/*
4
0 1 2 3
5 1 2 3
// 4 5 6
// 7 8 9
//10 11 12 13 14 15 16 17 18 19 20 21
//22 23 24 25 26 27 28 29 30 31 32 33
//34 35 36 37 38 39 40 41 42 43 44 45
// 46 47 48
// 49 50 51
// 52 53 54
*/
int cent[] = {, , , , , };
int face[][] = {
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,}
};
int change[][] = {
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,}
};
char s[];
int a[],b[];
int maxdepth;
int l = ;
bool dfs(int dep);
bool judge();
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
l = ;
for(int i = ;i <= ; ++i)
scanf(" %c",s+i);
//for(int i = 1; i <= 54; ++i)
// printf("%c",s[i]);
for(maxdepth = ;maxdepth <= ; ++maxdepth)
{
if(dfs())
{
if(l == )
{
printf("0\n");break;
}
printf("%d\n", l);
for(int i = ; i < l-; ++i)
{
printf("%d %d ",a[i],b[i]);
}
printf("%d %d\n",a[l-],b[l-]);
break;
}
}
if(maxdepth == )
printf("-1\n");
}
}
bool judge()
{
for(int i = ; i < ; ++i)
{
for(int j = ; j < ; ++j)
{
if(s[face[i][j]] != s[cent[i]])
return false;
}
}
return true;
}
bool dfs(int dep)
{
if(judge())
{
l = dep;
return true;
}
if(dep >= maxdepth)
return false;
char tmp[];
memcpy(tmp,s,sizeof s);
for(int i = ; i < ; ++i)
{
for(int j = ; j < ; ++j)
{
s[change[i][j]] = tmp[change[i^][j]];
}
/*if(dep == 0)
{
for(int i = 0; i < 6; ++i)
for(int j = 0; j < 9; ++j)
printf("%c",s[face[i][j]]);
cout << " " << (i&1) << endl;
cout << endl;
}*/
a[dep] = i/;
b[dep] = i&?-:;
if(dfs(dep+)) return true;
memcpy(s,tmp,sizeof tmp);
}
return false;
}
05-11 11:07