Spring-1-F Dice(HDU 5012)解题报告及测试数据
Dice
Time Limit:1000MS Memory Limit:65536KB
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.
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
题解:
正确表示正方体,用a1-a6表示。注意a1-a6分别表示的是上下左右前后六个面,顺序不能换。
使用map记录步数,以及查看该状态是否已经尝试过。
广度优先搜索,求得的结果即是最少的步数。
注意翻转后的数组不要写错。
以下是代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <sstream>
#include <queue>
#include <stack>
#include <stack>
#include <map>
using namespace std; #define F(i,s,e) for(int i = s;i<e;i++)
#define ss(x) scanf("%d",&x)
#define write() freopen("1.in","r",stdin)
#define W(x) while(x) string s1,s2;
string change(string str,int k){//1 l 2 r 3 f 4 b
string s="";
int a[6]={0,1,2,3,4,5};
switch(k){//实现四种翻转
case 1:a[0]=2;a[1]=3;a[2]=1;a[3]=0;break;
case 2:a[0]=3;a[1]=2;a[2]=0;a[3]=1;break;
case 3:a[0]=4;a[1]=5;a[4]=1;a[5]=0;break;
case 4:a[0]=5;a[1]=4;a[4]=0;a[5]=1;break;
}
F(i,0,6)s+=str[a[i]];
return s;
}
int bfs(){
map<string ,int > ma;//记录步数
queue<string>q;
string t1,t2;
ma[s1]=0;
q.push(s1);
W(!q.empty()){
t1 = q.front();
q.pop();
if(t1 == s2)return ma[t1];
F(i,1,5){
t2 = change(t1,i);
if(ma.find(t2)==ma.end()){//广度优先
q.push(t2);
ma[t2]=ma[t1]+1;
}
}
}
return -1;
} int main(){
//write();
int t;
W(ss(t)!=EOF){
s1=s2="";
s1+=t+'0';
F(i,0,5){
ss(t);
s1+=t+'0';
}
F(i,0,6){
ss(t);
s2+=t+'0';
}
cout << bfs()<<endl;
}
}
Spring-1-F Dice(HDU 5012)解题报告及测试数据的更多相关文章
- BestCoder18 1002.Math Problem(hdu 5105) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5105 题目意思:给出一个6个实数:a, b, c, d, l, r.通过在[l, r]中取数 x,使得 ...
- BestCoder17 1002.Select(hdu 5101) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...
- BestCoder12 1002.Help him(hdu 5059) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否 ...
- BestCoder10 1001 Revenge of Fibonacci(hdu 5018) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5018 题目意思:给出在 new Fibonacci 中最先的两个数 A 和 B(也就是f[1] = A ...
- BestCoder7 1002 Little Pony and Alohomora Part I(hdu 4986) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4986 题目意思:有 n 个box(从左到右编号依次为1~n),每个box里面有一个随机的钥匙,有可能这 ...
- BestCoder8 1001.Summary(hdu 4989) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4989 题目意思:给出 n 个数,然后将这些数两两相加,得到 n*(n-1) /2 对和,把重复的和去掉 ...
- BestCoder24 1001.Sum Sum Sum(hdu 5150) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5150 题目意思:就是直接求素数. 不过 n = 1,也属于答案范围!!只能说,一失足成千古恨啊---- ...
- BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...
- BestCoder20 1002.lines (hdu 5124) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段 ...
随机推荐
- hdu 4003(树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4003 思路:dp[i][j]表示以i为根选择j个机器人的最小花费,然后就是背包了:dp[u][i]=m ...
- sql列转行查询
test表: 执行列转行sql: select student, sum(case Course when '语文' then Score else null end) 语文, sum(case Co ...
- Oracle正式发布VirtualBox 5.0.22版本
甲骨文(Oracle)正式发布了VirtualBox 5.0.22版本,该开源和跨平台虚拟化软件的最新维护版本已经面向所有支持平台开放,引入了诸多新特性和功能改善推荐用户尽早完成升级.新版本在Linu ...
- hammer.js移动端手势库
hammer.js 是一个多点触摸手势库,能够为网页加入Tap.Double Tap.Swipe.Hold.Pinch.Drag等多点触摸事件,免去自己监听底层touchstart.touchmove ...
- Groovy中的脚本与类
包名 当你在groovy中定义类的时候需要指定包名,这和java中类似不多介绍. 导入 groovy中的导入也跟java类似,有一下五种: 默认导入 groovy默认导入了一下几个包和类: impor ...
- Golang学习-第一篇 Golang的简单介绍及Windows环境下安装、部署
序言 这是本人博客园第一篇文章,写的不到位之处,希望各位看客们谅解. 本人一直从事.NET的开发工作,最近在学习Golang,所以想着之前学习的过程中都没怎么好好的将学习过程记录下来.深感惋惜! 现在 ...
- OSharp DbContent初始化分析
DBContent初始化 —— 关联Entity查找 一. 关联到具体的Entity 二. 通过EntityTypeConfiguration 关联到DbContent 三. ...
- webpack4学习笔记(二)
webpack打包各种javascript文件 (本文只是提供一个学习记录,大部分内容来自网络) 一,打包js文件和es6代码 1,webpack命令打包js文件 Tip: 在webpack4.x之前 ...
- django将数据库中数据直接传到html
1.当然,前提是建立和配置好django数据库啦~ 2.在python后台函数中引入需要的表 #要读取home这个APP下的models.py文件,引入其中的Student_message_unedi ...
- Androidstudio中导入内部依赖模块总结
今天刚从GitHub上找了一个不错的项目,想要把它导入自己的项目中,过程中也遇到了一些小问题,总结一下,以便复习回顾!!!! 1.首先将从GitHub上下载的压缩包进行解压,找到其中的项目文件,直接复 ...