There are 2 special dices on the table. On each face of the dice, a distinct number was written. Consider a 1.a 2,a 3,a 4,a 5,a 6 to be numbers written on top face, bottom face, left face, right face, front face and back face of dice A. Similarly, consider b 1.b 2,b 3,b 4,b 5,b 6 to be numbers on specific faces of dice B. It’s guaranteed that all numbers written on dices are integers no smaller than 1 and no more than 6 while a i ≠ a j and b i ≠ b j for all i ≠ j. Specially, sum of numbers on opposite faces may not be 7.
At the beginning, the two dices may face different(which means there exist some i, a i ≠ b i). Ddy wants to make the two dices look the same from all directions(which means for all i, a i = b i) only by the following four rotation operations.(Please read the picture for more information)
Now Ddy wants to calculate the minimal steps that he has to take to achieve his goal.
Input
There are multiple test cases. Please process till EOF.
For each case, the first line consists of six integers a 1,a 2,a 3,a 4,a 5,a 6, representing the numbers on dice A.
The second line consists of six integers b 1,b 2,b 3,b 4,b 5,b 6, representing the numbers on dice B.
Output
For each test case, print a line with a number representing the answer. If there’s no way to make two dices exactly the same, output -1.
Sample Input
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 5 6 4 3 1 2 3 4 5 6 1 4 2 5 3 6
Sample Output
0 3 -1
题意,比较简单,就是给你两个骰子,然后让你使得第一个骰子和第二个变得一模一样,看你需要多少次转换,如果不能的话,输出-1,操作步骤分别可以向前翻,向后翻,向左翻,向后翻,先把这四种状态写下来,然后深搜走下去,每次更新最小值,看看是否可以。
#include<stdio.h>
#include<string.h>
int a[7],b[7],sum;
/*int left(int *s)
{
s[0]=a[4];
s[1]=a[5];
s[2]=a[2];
s[3]=a[3];
s[4]=a[1];
s[5]=a[0];
}
int right(int *s)
{
s[0]=a[5];
s[1]=a[4];
s[2]=a[2];
s[3]=a[3];
s[4]=a[0];
s[5]=a[1];
}
int front(int *s)
{
s[0]=a[2];
s[1]=a[3];
s[2]=a[1];
s[3]=a[0];
s[4]=a[4];
s[5]=a[5];
}
int back(int *s)
{
s[0]=a[3];
s[1]=a[2];
s[2]=a[0];
s[3]=a[1];
s[4]=a[4];
s[5]=a[5];
}*/
int dfs(int a[],int x)
{
if(x>4)
return 0;
int flag=1;
if(a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3]&&a[4]==b[4]&&a[5]==b[5])
flag=0;
if(flag)
{
int s[7];
s[0]=a[4];
s[1]=a[5];
s[2]=a[2];
s[3]=a[3];
s[4]=a[1];
s[5]=a[0];
dfs(s,x+1);
s[0]=a[5];
s[1]=a[4];
s[2]=a[2];
s[3]=a[3];
s[4]=a[0];
s[5]=a[1];
dfs(s,x+1);
s[0]=a[2];
s[1]=a[3];
s[2]=a[1];
s[3]=a[0];
s[4]=a[4];
s[5]=a[5];
dfs(s,x+1);
s[0]=a[3];
s[1]=a[2];
s[2]=a[0];
s[3]=a[1];
s[4]=a[4];
s[5]=a[5];
dfs(s,x+1);
}
else
{
if(sum>x)
sum=x;
}
}
int main()
{
while(~scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5]))
{
for(int i=0; i<6; i++)
scanf("%d",&b[i]);
sum=0x3f3f3f3f;
dfs(a,0);
if(sum==0x3f3f3f3f)
printf("-1\n");
else
printf("%d\n",sum);
}
return 0;
}