hdu 5012 Dice
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)

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.
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
3
-1
题意:两个骰子,要把第一个骰子转到和第二个一样,有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的更多相关文章
- HDU 5012 Dice (BFS)
事实上是非常水的一道bfs,用字符串表示每一个状态,map判重就ok了. 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5012 #include&l ...
- 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 ...
- HDU 5012 Dice DFS
简单DFS //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h ...
- Spring-1-F Dice(HDU 5012)解题报告及测试数据
Dice Time Limit:1000MS Memory Limit:65536KB Description There are 2 special dices on the table. ...
- HDU 5012 骰子旋转(DFS)
http://acm.hdu.edu.cn/showproblem.php?pid=5012 保存骰子的状态,然后用dfs或者bfs搜索 还是再讲一下dfs 我们的目标是找一个与b相同,且转次数最少的 ...
- hdu 5012 模拟+bfs
http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...
- hdu 5012 bfs --- 慎用STL 比方MAP判重
http://acm.hdu.edu.cn/showproblem.php?pid=5012 发现一个问题 假设Sting s = '1'+'2'+'3'; s!="123"!!! ...
- HDU 4652 Dice(期望)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意:一个m个面的筛子.两种询问:(1)平均抛多少次后使得最后n次的面完全一样:(2)平均抛多少 ...
- HDU 4652 Dice:期望dp(成环)【错位相减】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意: 给你一个有m个面的骰子. 两种询问: (1)"0 m n": “最后 ...
随机推荐
- 【顽固BUG】Visual Studio 2013 + TestDriven.NET-3.8.2860_Personal_Beta 调用的目标发生了异常。
前言 突然怎么弄也无法断点调试了 输出如下: ------ Test started: Assembly: Server5.V2.dll ------ 调用的目标发生了异常. 而且网站运行提示: -- ...
- ETL-Career RoadMap
RoadMap: 1.Tester:sql的单体或批处理测试: 2. Application Developer 2.1 批处理手动工具(如何使用.如何调度批处理.如何生成批处理脚本): 2.2 批处 ...
- 基于mapreducer的图算法
作者现就职阿里巴巴集团1688技术部 引言 周末看到一篇不错的文章"Graph Twiddling in a MapReduce world" ,介绍MapReduce下一些图算法 ...
- openwrt上网配置的一些理解(四)
这次要解决的问题是3g上网和wan口上往可以随意切换,当然能够叠加也是好事,不过这不是我关心的.下面还是修改3个文件network,firewall,multiwan.首先在network中加入界面配 ...
- MongoDB每64位版本下载
MongoDB每64位版本下载: http://dl.mongodb.org/dl/win32/x86_64 版权声明:本文博主原创文章,博客,未经同意不得转载.
- Android的深度定制版阿里云os(Android的山寨)
阿里云OS(YunOS)是阿里巴巴集团的智能手机操作系统,依托于阿里巴巴集团电子商务领域积累的经验和强大的云计算平台,基于LINUX开发. 魅族4阿里yun OS版已上市.[1] 1简介 阿 里云OS ...
- Chrome Browser
set default search engine as follow for force encrypted searching: https://encrypted.google.com/sear ...
- No suitable authentication method found to complete authentication (publickey,keyboard-interactive).
string command = Command.Text; StringBuilder result = new StringBuilder(); try { var connectionInfo ...
- 第一个Delphi小程序
第一次应工作需呀,接触这个语言,今晚在自己的电脑搭建好环境,写的第一个超简单的Delphi小程序! var temp:Integer; //求个位数 procedure TForm1.BitBtn1C ...
- 高性能ORM框架XLinq功能详细介绍
之前简单介绍了XLinq的一些功能,有很多功能都没有提到,现在给XLinq加了一些功能,这次把所有功能都介绍一遍. 设计目标 易用性 在使用一个框架的时候 应该没几个人会喜欢写一大堆的配置文件吧 也应 ...