# Dice

http://acm.hdu.edu.cn/showproblem.php?pid=5012

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2352    Accepted Submission(s): 1178

Problem Description
There are 2 special dices on the table. On each face of the dice, a distinct number was written. Consider a1.a2,a3,a4,a5,a6 to be numbers written on top face, bottom face, left face, right face, front face and back face of dice A. Similarly, consider b1.b2,b3,b4,b5,b6 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 ai ≠ aj and bi ≠ bj 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, ai ≠ bi). Ddy wants to make the two dices look the same from all directions(which means for all i, ai = bi) 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 a1,a2,a3,a4,a5,a6, representing the numbers on dice A.

The second line consists of six integers b1,b2,b3,b4,b5,b6, 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

Source

模拟搜索水题  ```  1 #include<iostream>
2 #include<cstring>
3 #include<algorithm>
4 #include<cmath>
5 #include<string>
6 #include<cstdio>
7 #include<queue>
8 #include<map>
9 #include<vector>
10 typedef long long ll;
11 #define maxn 100005
12 using namespace std;
13
14 int a,b;
15 map<int,int>mp;
16 struct sair{
17     int num,step;
18 };
19
20 sair Roll(sair tmp,int x){
21     //左右前后
22     sair ans;
23     ans.num=0;
24     int aa;
25     int xx=tmp.num;
26     for(int i=6;i>=1;i--){
27         a[i]=xx%10;
28         xx/=10;
29     }
30     if(x==0){
31         ans.num=ans.num*10+a;
32         ans.num=ans.num*10+a;
33         ans.num=ans.num*10+a;
34         ans.num=ans.num*10+a;
35         ans.num=ans.num*10+a;
36         ans.num=ans.num*10+a;
37     }
38     else if(x==1){
39         ans.num=ans.num*10+a;
40         ans.num=ans.num*10+a;
41         ans.num=ans.num*10+a;
42         ans.num=ans.num*10+a;
43         ans.num=ans.num*10+a;
44         ans.num=ans.num*10+a;
45     }
46     else if(x==2){
47         ans.num=ans.num*10+a;
48         ans.num=ans.num*10+a;
49         ans.num=ans.num*10+a;
50         ans.num=ans.num*10+a;
51         ans.num=ans.num*10+a;
52         ans.num=ans.num*10+a;
53     }
54     else{
55         ans.num=ans.num*10+a;
56         ans.num=ans.num*10+a;
57         ans.num=ans.num*10+a;
58         ans.num=ans.num*10+a;
59         ans.num=ans.num*10+a;
60         ans.num=ans.num*10+a;
61     }
62     ans.step=tmp.step+1;
63     return ans;
64 }
65
66 void bfs(int S,int E){
67     sair s,e;
68     if(S==E){
69         cout<<0<<endl;
70         return;
71     }
72     s.num=S,s.step=0;
73     queue<sair>Q;
74     Q.push(s);
75     while(!Q.empty()){
76         s=Q.front();
77         Q.pop();
78         for(int i=0;i<4;i++){
79             e=Roll(s,i);
80             if(e.num==E){
81                 cout<<e.step<<endl;
82                 return;
83             }
84             if(!mp[e.num]){
85                 Q.push(e);
86                 mp[e.num]=1;
87             }
88         }
89     }
90     cout<<-1<<endl;
91 }
92
93 int main(){
94     while(cin>>a){
95         mp.clear();
96         for(int i=2;i<=6;i++) cin>>a[i];
97         int S=0,E=0;
98         for(int i=1;i<=6;i++) E=E*10+a[i];
99         for(int i=1;i<=6;i++) cin>>b[i];
100         for(int i=1;i<=6;i++) S=S*10+b[i];
101         bfs(S,E);
102     }
103 }```
View Code
• 相关阅读:
operator模块和functools模块
函数注解
用户定义的可调用类型、从定位参数到仅限关键字参数
可调用对象
nxos启动的初始化和https访问nx-api
网络安全基础之网络协议与安全威胁
华为AC中服务集命令解释配置
转：图解ARP协议（四）代理ARP原理与实践（“善意的欺骗”）
windows下python3 python2 共存下安装virtualenvwrapper
关于网络安全学习的网站
• 原文地址：https://www.cnblogs.com/Fighting-sh/p/9943043.html