HDU 5012 Dice (BFS)
事实上是非常水的一道bfs,用字符串表示每一个状态,map判重就ok了。
题目链接:http://acm.hdu.edu.cn/showproblem.php?
pid=5012
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<string>
#include<queue>
#include<map>
#define N 7
using namespace std; string a,b;
map<string,int> Hash;
struct node
{
int t;
string v;
};
int rot[4][7]={ //Rotation operation
{0,4,3,1,2,5,6}, //left
{0,3,4,2,1,5,6}, //right
{0,6,5,3,4,1,2}, //front
{0,5,6,3,4,2,1}, //back
};
int bfs()
{
queue<node> q;
node u,v;
u.t=0; u.v=b;
q.push(u);
Hash[b]=1;
while(!q.empty())
{
u=q.front();
q.pop();
if(u.v==a)
return u.t;
for(int i=0;i<4;i++)
{
v.v="";
for(int j=1;j<7;j++)
v.v+=u.v[rot[i][j]-1]; //~~
if(!Hash[v.v])
{
v.t=u.t+1;
q.push(v);
Hash[v.v]=1;
}
}
}
return -1;
}
int main()
{
string t;
while(cin>>t)
{
a=b="";
a+=t;
for(int i=2;i<=6;i++)
{
cin>>t;
a+=t;
}
for(int j=1;j<=6;j++)
{
cin>>t;
b+=t;
}
Hash.clear();
cout<<bfs()<<endl;
}
return 0;
}
HDU 5012 Dice (BFS)的更多相关文章
- HDU 4652 Dice(期望)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意:一个m个面的筛子.两种询问:(1)平均抛多少次后使得最后n次的面完全一样:(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 ...
- HDU 1104 Remainder (BFS)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1104 题意:给你一个n.m.k,有四种操作n+m,n-m,n*m,n%m,问你最少经过多少步,使得最后 ...
- HDU 1175 连连看(BFS)
连连看 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 1240 Asteroids!(BFS)
题目链接:点击链接 简单BFS,和二维的做法相同(需注意坐标) 题目大意:三维的空间里,给出起点和终点,“O”表示能走,“X”表示不能走,计算最少的步数 #include <iostream&g ...
- HDU.1495 非常可乐 (BFS)
题意分析 大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为.因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多 ...
- HDU 4707 Pet(BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4707 题目大意:在一个无环的,从0开始发散状的地图里,找出各个距离0大于d的点的个数 Sample I ...
- hdu 1242 Rescue(bfs)
此刻再看优先队列,不像刚接触时的那般迷茫!这也许就是集训的成果吧! 加油!!!优先队列必须要搞定的! 这道题意很简单!自己定义优先级别! +++++++++++++++++++++++++++++++ ...
- HDU.2612 Find a way (BFS)
HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...
随机推荐
- DIV水平和垂直居中的实现
在div的宽度和高度固定的情况下,实现div水平和垂直居中普遍采用如下的方式: <!DOCTYPE html> <html> <head> <style ty ...
- surfaceflinger中各个layer的排序
surfaceflinger的主要工作就是负责把上层传递下来的各个不同的layer进行composition. 这里,我们来讨论一下各个layer在surfaceflinger中的上下排序关系和相关的 ...
- Navicat工具破解
Navicat提供多达 7 种语言供客户选择,被公认为全球最受欢迎的数据库前端用户介面工具.它可以用来对本机或远程的 MySQL.SQL Server.SQLite.Oracle 及 Post ...
- sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
在使用Hibernate的J2EE项目中,莫名其妙出现如上错误,既不报错,也不运行不论什么输出測试代码,更不返回结果. 经过排查,在方法里面引用的实体类和其映射文件属性个数不一致. 改动一致后,即解决 ...
- ibatis dynamic的用法
<select id="idididid" resultClass="java.uitl.HashMap" parameterClass="ja ...
- 【HDU】5248-序列变换(贪心+二分)
二分枚举长度改变的长度即可了 #include<cstdio> #include<cstring> #include<algorithm> using namesp ...
- Xamarin For Visual Studio 3.7.165 完整离线破解版
原文 Xamarin For Visual Studio 3.7.165 完整离线破解版 Xamarin For Visual Studio就是原本的Xamarin For Android 以及 Xa ...
- 【Linux驱动】TQ2440 LED驱动程序
★整体介绍 LED驱动程序主要实现了TQ2440开发板上的4个LED灯的硬件驱动,实现了对引脚GPIOB5.GPIOB6.GPIOB7.GPIOB8的高低电平设置(common-smdk.c中已经实现 ...
- BZOJ 2783 JLOI 2012 树 乘+二分法
标题效果:鉴于一棵树和一个整数s,问中有树木几个这样的路径,点和担保路径==s,深度增量点. 这一数额的输出. 思维:用加倍的想法,我们可以O(logn)在时间找点他第一n.因为点权仅仅能是正的,满足 ...
- vim使用(三):.viminfo和.vimrc
1. viminfo 在vim中操作的行为,vim会自己主动记录下来,保存在 ~/.viminfo 文件里. 这样为了方便下次处理, 如:vim打开文件时,光标会自己主动在上次离开的位置显示. 原来搜 ...