hdu5012 bfs
比较简单的题 搜索4个方向,维护位子的值。
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int a[],b[];
int vis[][][][][][];
struct node
{
int x1,x2,x3,x4,x5,x6,step;
};
int bfs()
{
queue<node>q;
node temp;
temp.x1=a[];temp.x2=a[];temp.x3=a[];temp.x4=a[];temp.x5=a[];temp.x6=a[];temp.step=;
q.push(temp);
while(!q.empty())
{
int i;
node tt;
tt=q.front();
q.pop();
if(tt.x1==b[]&&tt.x2==b[]&&tt.x3==b[]&&tt.x4==b[]&&tt.x5==b[]&&tt.x6==b[])
return tt.step;
for(i=;i<=;i++)
{
node ret;
if(i==){//left
ret.x1=tt.x4;ret.x2=tt.x3;ret.x3=tt.x1;
ret.x4=tt.x2;ret.x5=tt.x5;ret.x6=tt.x6;
}
else if(i==){//right
ret.x1=tt.x3;ret.x2=tt.x4;ret.x3=tt.x2;
ret.x4=tt.x1;ret.x5=tt.x5;ret.x6=tt.x6;
}
else if(i==){//front
ret.x1=tt.x6;ret.x2=tt.x5;ret.x3=tt.x3;
ret.x4=tt.x4;ret.x5=tt.x1;ret.x6=tt.x2;
}
else if(i==){//back
ret.x1=tt.x5;ret.x2=tt.x6;ret.x3=tt.x3;
ret.x4=tt.x4;ret.x5=tt.x2;ret.x6=tt.x1;;
}
if(!vis[ret.x1][ret.x2][ret.x3][ret.x4][ret.x5][ret.x6])
{
vis[ret.x1][ret.x2][ret.x3][ret.x4][ret.x5][ret.x6]=;
ret.step=tt.step+;
q.push(ret);
}
}
}
return -;
}
int main()
{
int i,j;
while(scanf("%d%d%d%d%d%d",&a[],&a[],&a[],&a[],&a[],&a[])!=EOF)
{
for(i=;i<=;i++)
scanf("%d",&b[i]); for(i=;i<=;i++)
for(j=;j<=;j++)
for(int k=;k<=;k++)
for(int f=;f<=;f++)
for(int g=;g<=;g++)
for(int h=;h<=;h++)
vis[i][j][k][f][g][h]=;
int ans=bfs();
if(ans==-)
printf("-1\n");
else printf("%d\n",ans);
}
}
hdu5012 bfs的更多相关文章
- HDU5012:Dice(bfs模板)
http://acm.hdu.edu.cn/showproblem.php?pid=5012 Problem Description There are 2 special dices on the ...
- hdu 5012 bfs --- 慎用STL 比方MAP判重
http://acm.hdu.edu.cn/showproblem.php?pid=5012 发现一个问题 假设Sting s = '1'+'2'+'3'; s!="123"!!! ...
- 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)
图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...
- 【BZOJ-1656】The Grove 树木 BFS + 射线法
1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 186 Solved: 118[Su ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- Sicily 1215: 脱离地牢(BFS)
这道题按照题意直接BFS即可,主要要注意题意中的相遇是指两种情况:一种是同时到达同一格子,另一种是在移动时相遇,如Paris在(1,2),而Helen在(1,2),若下一步Paris到达(1,1),而 ...
- Sicily 1048: Inverso(BFS)
题意是给出一个3*3的黑白网格,每点击其中一格就会使某些格子的颜色发生转变,求达到目标状态网格的操作.可用BFS搜索解答,用vector储存每次的操作 #include<bits/stdc++. ...
- Sicily 1444: Prime Path(BFS)
题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...
随机推荐
- poj1274 The Perfect Stall (二分最大匹配)
Description Farmer John completed his new barn just last week, complete with all the latest milking ...
- HDU 3487 Play with Chain 【Splay】
1-n的序列,有两种操作: 1,将一段区间翻转 2,将一段区间切下来放到剩余序列的第C个数后 采用延迟更新的方法维护区间的翻转,并维护一个size域. 添加一个最大点和一个最小点,防止出界 翻转时,将 ...
- map学习笔记
collection是单列集合,map是双列集合.其中包含<k,v>键值对,注意:键具有唯一性,而值不唯一. 在此列举三个读取方式:keyset,valueset,及entryset. k ...
- [转]Source Insight使用小技巧小结
Source Insight是一款强大的代码查看工具,本身支持扩展性很好.下面我们就介绍2个扩展用例. 1.快速打开当前文件所在的目录,这个功能类似于eclipse的easyshell插件,就是能快速 ...
- Volley(一 )—— 框架简介
一.引言 虽然网上已经有很多大神.高手都写过了类似的帖子,但作为新人,必须要走模仿的道路,再考虑超越,因此学习大神的笔记,记录自己的理解,是一个菜鸟走向成功的必经之路啊.如签名所言,记录自己摸爬滚打的 ...
- Oracle中没有 if exists(...)
对于Oracle中没有 if exists(...) 的语法,目前有许多种解决方法,这里先分析常用的三种,推荐使用最后一种 第一种是最常用的,判断count(*)的值是否为零,如下declare v ...
- [Usaco2010 OPen]Triangle Counting 数三角形
[Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 394 Solved: 1 ...
- 12SpringMvc_在业务控制方法中写入普通变量收集参数
这篇文章讲的是jsp页面不是会传一些参数到Action中,那么Action怎么去接受这个数据呢? 方案: 案例结构如下:
- 复习做UWP时涉及到的几种加密签名相关
本人菜鸟一枚,大学里凭兴趣学了一点WP的皮毛,后来又幸运(或者不幸)的进了一家专注于Windows生态的公司做了一段时间的UWP.在博客园写点自己遇到的东西,作为分享,也作为自己的备忘,如果有错误的地 ...
- Django1.10环境安装
在Ubuntu14上 一 安装脚本 wget https://github.com/django/django/archive/master.tar.gz apt-get install python ...