Dice
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 117 Accepted Submission(s): 67
Problem Description
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.
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)
![](https://i-blog.csdnimg.cn/blog_migrate/4d5d5c19f17f92722270306477e25374.jpeg)
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.
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今天做网络赛的时候,一直以为是一道计算几何的题,后来在队友L的提醒下,才发现竟是一道BFS,无语的一遍就过了,英语还是最大的障碍啊题意:给定两个正方体,六个面上分别为1,2,3,4,5,6,一个正方体可以有四种操作,即向前,向后,向左,向右翻转,问最少翻转多少次两个正方体对应面上的数字完全相同,如若不能输出-1AC代码如下#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> using namespace std; struct node { int s1,s2,s3,s4,s5,s6; int sum; } q[800000]; int a[7],b[7]; int c[7][7][7][7][7][7]; void bfs() { memset(c,0,sizeof(c)); struct node t,r; t.s1=b[1]; t.s2=b[2]; t.s3=b[3]; t.s4=b[4]; t.s5=b[5]; t.s6=b[6]; t.sum=0; int k=0,l=0; q[l++]=t; while(k<l) { t=q[k++]; if(t.s1==a[1] && t.s2==a[2] && t.s3==a[3] && t.s4==a[4] && t.s5==a[5] && t.s6==a[6]) { printf("%d\n",t.sum); return ; } for(int i=0; i<4; i++) { if(i==0) { r.s1=t.s4; r.s2=t.s3; r.s3=t.s1; r.s4=t.s2; r.s5=t.s5; r.s6=t.s6; } else if(i==1) { r.s1=t.s3; r.s2=t.s4; r.s3=t.s2; r.s4=t.s1; r.s5=t.s5; r.s6=t.s6; } else if(i==2) { r.s1=t.s5; r.s2=t.s6; r.s3=t.s3; r.s4=t.s4; r.s5=t.s2; r.s6=t.s1; } else { r.s1=t.s6; r.s2=t.s5; r.s3=t.s3; r.s4=t.s4; r.s5=t.s1; r.s6=t.s2; } if(!c[r.s1][r.s2][r.s3][r.s4][r.s5][r.s6]) { c[r.s1][r.s2][r.s3][r.s4][r.s5][r.s6]=1; r.sum=t.sum+1; q[l++]=r; } } } printf("-1\n"); } int main() { while(~scanf("%d",&a[1])) { for(int i=2; i<=6; i++) scanf("%d",&a[i]); for(int i=1; i<=6; i++) scanf("%d",&b[i]); /*int f1=0,f2=0; for(int i=1;i<=6;i+=2) //比赛中这样做的,是直接判断对应面上的数字是否相同,否则直接输出-1,后发现去掉这一步也可以,直接在BFS中输出-1 { if((a[1]==b[i]&&a[2]==b[i+1]) ||(a[2]==b[i]&&a[1]==b[i+1])) f1=1; if((a[3]==b[i]&&a[4]==b[i+1]) ||(a[4]==b[i]&&a[3]==b[i+1])) f2=1; }*/ //if(f1&&f2) bfs(); // else printf("-1\n"); } return 0; }