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
 

题意:两个骰子,要把第一个骰子转到和第二个一样,有4种转法,求最少的次数

直接bfs,不过我用G++提交超时,用C++提交可以过,可能是使用了queue的原因。。。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
struct Node
{
int a[];
int t;
}st,ed;
int vis[][][][][][];
void bfs()
{ queue<Node>q;
q.push(st); vis[st.a[]][st.a[]][st.a[]][st.a[]][st.a[]][st.a[]]=;
Node t1,t2;
Node tmp;
while(!q.empty())
{
t1=q.front();
q.pop();
if(t1.a[]==ed.a[] && t1.a[]==ed.a[]&& t1.a[]==ed.a[]&& t1.a[]==ed.a[]&& t1.a[]==ed.a[] && t1.a[]==ed.a[])
{
printf("%d\n",t1.t);
return;
} t2=t1;
t2.a[]=t1.a[];
t2.a[]=t1.a[];
t2.a[]=t1.a[];
t2.a[]=t1.a[];
if(vis[t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]]==)
{
vis[t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]]=;
t2.t=t1.t+;
q.push(t2);
} t2=t1;
t2.a[]=t1.a[];
t2.a[]=t1.a[];
t2.a[]=t1.a[];
t2.a[]=t1.a[];
if(vis[t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]]==)
{
vis[t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]]=;
t2.t=t1.t+;
q.push(t2);
} t2=t1;
t2.a[]=t1.a[];
t2.a[]=t1.a[];
t2.a[]=t1.a[];
t2.a[]=t1.a[];
if(vis[t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]]==)
{
vis[t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]]=;
t2.t=t1.t+;
q.push(t2);
} t2=t1;
t2.a[]=t1.a[];
t2.a[]=t1.a[];
t2.a[]=t1.a[];
t2.a[]=t1.a[];
if(vis[t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]]==)
{
vis[t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]][t2.a[]]=;
t2.t=t1.t+;
q.push(t2);
}
}
printf("-1\n");
}
int main()
{
while(scanf("%d%d%d%d%d%d",&st.a[],&st.a[],&st.a[],&st.a[],&st.a[],&st.a[])==)
{
scanf("%d%d%d%d%d%d",&ed.a[],&ed.a[],&ed.a[],&ed.a[],&ed.a[],&ed.a[]);
st.t=;
memset(vis,,sizeof(vis));
bfs();
}
return ;
}

hdu 5012 Dice的更多相关文章

  1. HDU 5012 Dice (BFS)

    事实上是非常水的一道bfs,用字符串表示每一个状态,map判重就ok了. 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5012 #include&l ...

  2. ACM学习历程—HDU 5012 Dice(ACM西安网赛)(bfs)

    Problem Description There are 2 special dices on the table. On each face of the dice, a distinct num ...

  3. HDU 5012 Dice DFS

    简单DFS //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h ...

  4. Spring-1-F Dice(HDU 5012)解题报告及测试数据

    Dice Time Limit:1000MS     Memory Limit:65536KB Description There are 2 special dices on the table. ...

  5. HDU 5012 骰子旋转(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 保存骰子的状态,然后用dfs或者bfs搜索 还是再讲一下dfs 我们的目标是找一个与b相同,且转次数最少的 ...

  6. hdu 5012 模拟+bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...

  7. hdu 5012 bfs --- 慎用STL 比方MAP判重

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 发现一个问题 假设Sting s = '1'+'2'+'3'; s!="123"!!! ...

  8. HDU 4652 Dice(期望)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意:一个m个面的筛子.两种询问:(1)平均抛多少次后使得最后n次的面完全一样:(2)平均抛多少 ...

  9. HDU 4652 Dice:期望dp(成环)【错位相减】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意: 给你一个有m个面的骰子. 两种询问: (1)"0 m n": “最后 ...

随机推荐

  1. [原创作品]观察者模式在Web App的应用

    (转载请注明:http://zhutty.cnblogs.com, 交流请加群:164858883) 在软件工程中,有一条重要的原则就是:高内聚低耦合.这是评定软件的设计好坏的一个标准.所谓高内聚,指 ...

  2. Python 线程池的原理和实现及subprocess模块

    最近由于项目需要一个与linux shell交互的多线程程序,需要用python实现,之前从没接触过python,这次匆匆忙忙的使用python,发现python确实语法非常简单,功能非常强大,因为自 ...

  3. Intent 意图 结构 简介

    Intent简介 官方解释: An intent is an abstract description of an operation操作 to be performed展示.表演. It can b ...

  4. SQL Server 2005无日志文件附加数据库

    公司网站运营两年多了,日志文件超级大,在重装系统的时候,为了省事,就没有备份日志文件,而且是没有分离就把日志文件给删掉了(下次一定要记得先分离再删日志文件).结果造成数据库怎么都附加不上.出现错误. ...

  5. ASP.NET常用编程代码(二)

    1.绑定在DataList中的DropDownList private void dlistOrder_EditCommand(object source, System.Web.UI.WebCont ...

  6. Lesson 2: Dive Into Typography (排版)

    Lesson 2: Dive Into Typography (排版) 排版是字的艺术,是关于字的一切:字体.字号.行高.行长.字重(斜体/加粗/正常).字距(kerning).行距(leading) ...

  7. [c#]asp.net开发微信公众平台(6)阶段总结、服务搭建、接入

    经过前5篇,跟着一步步来的话,任何人都能搭建好一个能处理各种微信消息的框架了,总结一下最容易忽略的问题: 1.文本消息中可以使用换行符\n    : 2.微信发来的消息中带的那个长整型的时间,我们完全 ...

  8. SVN中trunk,branches,tags用法详解

    原文地址:http://www.cnblogs.com/dafozhang/archive/2012/06/28/2567769.html Subversion有一个很标准的目录结构,是这样的.比如项 ...

  9. Qt5.4静态编译方法

    静态编译,就是编译器在编译可执行文件的时候,将可执行文件需要调用的对应动态链接库(.so或.lib)中的部分提取出来,链接到可执行文件中去,使可执行文件在运行的时候不依赖于动态链接库.这样就可以发布单 ...

  10. GitHub 相关内容

    1. Git是分布式版本控制系统 集中式版本控制系统:版本库是集中存放在中央服务器的,而干活的时候,用的都是自己的电脑,所以要先从中央服务器取得最新的版本,然后开始干活,干完活了,再把自己的活推送给中 ...