HDU 5012 Dice (bfs)
2014-09-14 19:37
483 查看
Dice
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 98 Accepted Submission(s): 57
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
2014 ACM/ICPC Asia Regional Xi'an Online
Recommend
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<vector> #define L(x) (x<<1) #define R(x) (x<<1|1) #define MID(x,y) ((x+y)>>1) using namespace std; #define N 700005 struct stud{ int a1,a2,a3,a4,a5,a0; int time; }s,e,t; int ans; int vis ; int fdd(struct stud x) { int temp=0; temp+=x.a0*1; temp+=x.a1*7; temp+=x.a2*7*7; temp+=x.a3*7*7*7; temp+=x.a4*7*7*7*7; temp+=x.a5*7*7*7*7*7; return temp; } stud fddd(stud cur,int i) { struct stud next; if(i==0) { next.a0=cur.a2; next.a1=cur.a3; next.a2=cur.a1; next.a3=cur.a0; next.a4=cur.a4; next.a5=cur.a5; } else if(i==1) { next.a0=cur.a3; next.a1=cur.a2; next.a2=cur.a0; next.a3=cur.a1; next.a4=cur.a4; next.a5=cur.a5; } else if(i==2) { next.a0=cur.a5; next.a1=cur.a4; next.a2=cur.a2; next.a3=cur.a3; next.a4=cur.a0; next.a5=cur.a1; } else { next.a0=cur.a4; next.a1=cur.a5; next.a2=cur.a2; next.a3=cur.a3; next.a4=cur.a1; next.a5=cur.a0; } return next; } int bfs() { int temp,i; struct stud cur,next; memset(vis,0,sizeof(vis)); temp=fdd(s); ans=fdd(e); vis[temp]=1; cur=s; cur.time=0; queue<stud>q; q.push(cur); while(!q.empty()) { cur=q.front(); q.pop(); if(fdd(cur)==ans) return cur.time; for(i=0;i<4;i++) //旋转 { stud t=fddd(cur,i); temp=fdd(t); if(!vis[temp]) { t.time=cur.time+1; q.push(t); vis[temp]=1; } } } return -1; } int main() { int i; while(~scanf("%d",&s.a0)) { scanf("%d%d%d%d%d",&s.a1,&s.a2,&s.a3,&s.a4,&s.a5); scanf("%d%d%d%d%d%d",&e.a0,&e.a1,&e.a2,&e.a3,&e.a4,&e.a5); printf("%d\n",bfs()); } }
相关文章推荐
- HDU 5012 Dice (BFS)
- HDU 5012 Dice (BFS)
- HDU 5012 Dice 普通bfs
- hdu 5012 Dice 2014 ACM/ICPC Asia Regional Xi'an Online bfs
- HDU 5012 Dice bfs
- HDU-#5012 Dice(BFS)
- hdu 5012 Dice BFS 2014 ACM/ICPC Asia Regional Xi'an Online
- hdu 5012 Dice(bfs)
- HDU 5012-Dice(BFS)
- hdu 5012 Dice(西安网络赛F题,BFS)
- HDU - 5012 Dice(bfs+hash)
- HDU - 5012 Dice(BFS)
- bfs-HDU 5012Dice
- ACM学习历程—HDU 5012 Dice(ACM西安网赛)(bfs)
- hdu 5012 Dice 记忆化搜索
- HDU 5012 Dice 隐式图的搜索
- BFS + 剪枝 之 hdu 5012 Dice
- hdu 5012__Dice
- hdu5012 Dice(分治限界法)
- hdu 5012 Dice