hdu 5012 Dice
2015-08-20 02:29
337 查看
[align=left]Problem Description[/align]
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)
View Code
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)
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<map> using namespace std; struct Node { int a[7]; int t; }st,ed; int vis[10][10][10][10][10][10]; void bfs() { queue<Node>q; q.push(st); vis[st.a[0]][st.a[1]][st.a[2]][st.a[3]][st.a[4]][st.a[5]]=1; Node t1,t2; Node tmp; while(!q.empty()) { t1=q.front(); q.pop(); if(t1.a[0]==ed.a[0] && t1.a[1]==ed.a[1]&& t1.a[2]==ed.a[2]&& t1.a[3]==ed.a[3]&& t1.a[4]==ed.a[4] && t1.a[5]==ed.a[5]) { printf("%d\n",t1.t); return; } t2=t1; t2.a[0]=t1.a[3]; t2.a[1]=t1.a[2]; t2.a[2]=t1.a[0]; t2.a[3]=t1.a[1]; if(vis[t2.a[0]][t2.a[1]][t2.a[2]][t2.a[3]][t2.a[4]][t2.a[5]]==0) { vis[t2.a[0]][t2.a[1]][t2.a[2]][t2.a[3]][t2.a[4]][t2.a[5]]=1; t2.t=t1.t+1; q.push(t2); } t2=t1; t2.a[0]=t1.a[2]; t2.a[1]=t1.a[3]; t2.a[2]=t1.a[1]; t2.a[3]=t1.a[0]; if(vis[t2.a[0]][t2.a[1]][t2.a[2]][t2.a[3]][t2.a[4]][t2.a[5]]==0) { vis[t2.a[0]][t2.a[1]][t2.a[2]][t2.a[3]][t2.a[4]][t2.a[5]]=1; t2.t=t1.t+1; q.push(t2); } t2=t1; t2.a[0]=t1.a[5]; t2.a[1]=t1.a[4]; t2.a[4]=t1.a[0]; t2.a[5]=t1.a[1]; if(vis[t2.a[0]][t2.a[1]][t2.a[2]][t2.a[3]][t2.a[4]][t2.a[5]]==0) { vis[t2.a[0]][t2.a[1]][t2.a[2]][t2.a[3]][t2.a[4]][t2.a[5]]=1; t2.t=t1.t+1; q.push(t2); } t2=t1; t2.a[0]=t1.a[4]; t2.a[1]=t1.a[5]; t2.a[4]=t1.a[1]; t2.a[5]=t1.a[0]; if(vis[t2.a[0]][t2.a[1]][t2.a[2]][t2.a[3]][t2.a[4]][t2.a[5]]==0) { vis[t2.a[0]][t2.a[1]][t2.a[2]][t2.a[3]][t2.a[4]][t2.a[5]]=1; t2.t=t1.t+1; q.push(t2); } } printf("-1\n"); } int main() { while(scanf("%d%d%d%d%d%d",&st.a[0],&st.a[1],&st.a[2],&st.a[3],&st.a[4],&st.a[5])==6) { scanf("%d%d%d%d%d%d",&ed.a[0],&ed.a[1],&ed.a[2],&ed.a[3],&ed.a[4],&ed.a[5]); st.t=0; memset(vis,0,sizeof(vis)); bfs(); } return 0; }
View Code
相关文章推荐
- 简析TCP的三次握手与四次挥手
- Gym 100418J Lucky tickets(数位dp)
- CC150-链表4
- hdu 5115 Dire Wolf【区间DP】
- optional
- wampserver环境下配置phpmyadmin远程访问mysql数据库
- uestc 94(区间更新)
- [Javascript] The "this" keyword
- C++ virtual关键字
- get set 用法
- 1034. Head of a Gang (30)
- 从实用主义深入理解c++虚函数
- hdu1085 Holding Bin-Laden Captive!
- JSON——JavaScript程序设计笔记(15)
- 安装Laravel之坎坷记述
- 安装Laravel之坎坷记述
- 【8-19】java学习笔记01
- POJ 2528 Mayor's posters (离散化 + 线段树)
- var_and_let
- cocos2dx 触摸钢琴