题干:

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

题目大意:

给出两个正方体,每个正方体都有6种颜色,问是否可以经过左转,右转,前转,后转四种转法让两个正方体看起来一样(对应面颜色相同),最少转几次。

解题报告:

直接bfs。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
vector<int> aa;
set<vector<int> > ss;
struct Node {vector<int> vv;int s;
};
int bfs(vector<int> st) {queue<Node> q;q.push({st,0});while(q.size()) {Node cur = q.front();q.pop();if(cur.vv == aa) return cur.s;if(ss.count(cur.vv)) continue;ss.insert(cur.vv);vector<int> t = cur.vv,nn(6);//Leftnn[0] = t[3],nn[1] = t[2],nn[2] = t[0],nn[3] = t[1],nn[4] = t[4],nn[5] = t[5];q.push({nn,cur.s+1});//Right nn[0] = t[2],nn[1] = t[3],nn[2] = t[1],nn[3] = t[0],nn[4] = t[4],nn[5] = t[5];q.push({nn,cur.s+1});//Frontnn[0] = t[5],nn[1] = t[4],nn[2] = t[2],nn[3] = t[3],nn[4] = t[0],nn[5] = t[1];q.push({nn,cur.s+1});//Backnn[0] = t[4],nn[1] = t[5],nn[2] = t[2],nn[3] = t[3],nn[4] = t[1],nn[5] = t[0];q.push({nn,cur.s+1});}return -1;
}
int main()
{int z,x,c,v,b,n;while(~scanf("%d%d%d%d%d%d",&z,&x,&c,&v,&b,&n)) {aa.clear(); ss.clear();vector<int> a(6);a[0]=z;a[1]=x;a[2]=c;a[3]=v;a[4]=b;a[5]=n;for(int i = 1; i<=6; i++) {scanf("%d",&x);aa.pb(x);}int ans = bfs(a);printf("%d\n",ans);} return 0 ;
}

【HDU - 5012】Dice(模拟,bfs)相关推荐

  1. poj1426_模拟BFS

    题意:给出一个200以内的数n,求出这个数的倍数M,使得M中只有0和1组成.M最多100位. 分析:这个题竟然用的是bfs的思想.不看讨论真的想不出来.思路是这样的: 1.最高位一定是1.curnum ...

  2. HDU - 1495 非常可乐(BFS,数学)

    HDU - 1495 非常可乐(BFS,数学) 巨佬的数学解法 #include<iostream> using namespace std; int gcd(int a,int b) { ...

  3. 2014 网选 5012 Dice(bfs模板)

    1 /* 2 题意:就是给定两个筛子,每个筛子上6个面,每个面的数字属于[1,6], 且互不相同! 3 问a筛子最少经过按照题目规定的要求转动,达到和b筛子上下左右前后的数字相同! 4 5 思路:很直 ...

  4. Hdu 1495 非常可乐、BFS、模拟:【题解】

    非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Descri ...

  5. HDU 2102 题解(BFS 广度优先搜索 练习题)

    原题链接,但是HDU现在校外提交需要审核 欢迎来 SCPC OJ提交 知识点 : BFS(广搜/宽搜) 原题: 描述: 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生 ...

  6. HDU 1104 Remainder (BFS)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1104 题意:给你一个n.m.k,有四种操作n+m,n-m,n*m,n%m,问你最少经过多少步,使得最后 ...

  7. HDU - 5335 Walk Out(bfs+路径输出+贪心)

    题目链接:点击查看 题目大意:给出一个矩阵,要求从(1,1)点走到(n,m)点,要求途径数字依次组成的二进制数字最小 题目分析:这个题我的心路历程真的是非常坎坷的,就来稍微记录一下吧,或许对以后做题能 ...

  8. csu 1536 Bit String Reordering(模拟 bfs+状态压缩)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1536 题意: 输入n个只为 0或1 的数 形成一个排列 再输入m个数 每个数代表 目标排列 (样例 ...

  9. HDU 4121 Xiangqi 模拟题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4121 首先对标题赞一个,非要叫 "Xiangqi" 而不是 "中国象棋&q ...

最新文章

  1. 从零开始学_JavaScript_系列(24)——查看对象属性,合并数组
  2. AMD宣布350亿美元收购赛灵思,CPU、GPU、FPGA全凑齐,中国握有否决权
  3. Python组织文件 实践:将文件的不同版本备份为ZIP文件
  4. onnxruntime c++ 工程实例
  5. 如何使用 50 行 Python 代码制作一个计算器
  6. php记录已经点击过,最近一次的PHP面试题记录,office已到手!
  7. 华为鸿蒙系统是否上线,华为官方:鸿蒙系统2.0上线,手机能否搭载鸿蒙操作系统?...
  8. 前端学习(3144):react-hello-react之对比新旧周期
  9. 二进制函数_Go二进制文件逆向分析从基础到进阶——MetaInfo、函数符号和源码文件路径列表...
  10. mysql防止预约重号_mysql 防止重复插入唯一限制的数据
  11. 解读知识蒸馏模型TinyBert
  12. ffmpeg 推流同时录像命令_ffmpeg推流命令
  13. shell 学习之for语句
  14. 缓冲文件系统和非缓冲文件系统
  15. acs880变频器静态辨识_ACS880变频器PID控制参数设置 -
  16. 使用国产化的TongWeb服务器使用手册
  17. java时间的格式化_java如何给时间格式化
  18. 计算机作业实验报告dw感想,Dreamweaver实验报告.doc
  19. 联想笔记本连不上手机热点_笔记本电脑连接不上手机热点该怎么解决?
  20. Linux学习笔记(1)--Linux的发展史

热门文章

  1. 85. Maximal Rectangle
  2. 【Breadth-first Search 】934. Shortest Bridge
  3. Depth-first Search深度优先搜索专题6
  4. [Leetcode][第40题][JAVA][数组总和2][回溯][剪枝]
  5. 从一个数组中找出最接近目标_LeetCode每日一题 | 转变数组后最接近目标值的数组和...
  6. 网页底部的版权信息_Shopify底部的版权信息(Powered by Shopify )如何删除
  7. pdf温度记录仪开发_蔬菜、鲜果、奶制品冷链温度监控系统监控食品让客户放心...
  8. nlp 命名实体识别 算法_中文命名实体识别算法 Lattice LSTM
  9. 用c语言编程减法计算,求用C编个大数加减法运算程序
  10. c#sql防注入模糊查询_SQL中利用LIKE实现模糊查询的功能