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 表示该条线段 ...
随机推荐
- ChemDraw怎么绘制H-点或H-划
ChemDraw软件是一款全球领先的化学绘图工具,能够绘制各类化学结构图形和化学方程式,在基础化学.有机化学和分析化学等领域得到了广泛的应用.H-点和H-划是日常作图过程中使用频率较高的化学符号,必须 ...
- iOS开发之--NSNotificationCenter的使用
NSNotification是IOS中一个调度消息通知的类,采用单例模式设计,在程序中实现传值.回调等地方应用很广 iOS中通知中心NSNotificationCenter应用总结 一.了解几个相关的 ...
- SecureCRT 常用技巧
转自:http://blog.chinaunix.net/uid-26575352-id-3063143.html 快捷键: 1. ctrl + a : 移动光标到行首 2. ctrl + e :移 ...
- 修改UE4的deriveddatacache目录位置,扩大C盘空间
按照默认安装目录,UE4会装在C盘 C:\Program Files\Epic Games\UE_4.15 DerivedDataCache缓存目录在 C:\Users\你的用户名\AppData\L ...
- Python学习笔记6-字典Dict
Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. >>> person ...
- 过滤一个Collection最好的方法
private static List<Integer> filter(List<Integer> list){ Iterator<Integer> it = li ...
- phpredis 中文手册和redis 教程
phpredis 中文手册 : http://www.cnblogs.com/zcy_soft/archive/2012/09/21/2697006.html 手册: http://www.cn ...
- 【黑金原创教程】【Modelsim】【第二章】Modelsim就是电视机
声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/al ...
- python裁剪base64编码的图片
简介 今天遇到需要裁剪base64字符串的PNG图片,并返回base64格式字符串的任务,捣鼓半天. 裁剪代码如下: def deal_inspect_img(base64_str): "& ...
- [Android Tips] 17. 查看 APK 签名信息
从 APK 文件中获取签名信息 方法一 $ keytool -list -printcert -jarfile <path of APK> 方法二 解压 APK 文件,释放出 META-I ...