HDU5012:Dice(bfs模板)
http://acm.hdu.edu.cn/showproblem.php?pid=5012
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.
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.
answer. If there’s no way to make two dices exactly the same, output -1.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
using namespace std;
int v[][][][][][];
struct node
{
int ff[];
int ans;
};
struct node t,f;
int a[],b[];
int bfs()
{
queue<node>q;
for(int i=; i<=; i++)
t.ff[i]=a[i];
t.ans=;
q.push(t);
v[t.ff[]][t.ff[]][t.ff[]][t.ff[]][t.ff[]][t.ff[]]=;
while(!q.empty())
{
t=q.front();
q.pop();
if(t.ff[]==b[]&&t.ff[]==b[]&&t.ff[]==b[]&&t.ff[]==b[]&&t.ff[]==b[]&&t.ff[]==b[])
{
printf("%d\n",t.ans);
return ;
}
for(int i=; i<=; i++)
{
if(i==)
{
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
if(v[f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]]==)
{
f.ans=t.ans+;
v[f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]]=;
q.push(f);
}
}
else if(i==)
{
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
if(v[f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]]==)
{
f.ans=t.ans+;
v[f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]]=;
q.push(f);
}
}
else if(i==)
{
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
if(v[f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]]==)
{
f.ans=t.ans+;
v[f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]]=;
q.push(f);
}
}
else if(i==)
{
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
f.ff[]=t.ff[];
if(v[f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]]==)
{
f.ans=t.ans+;
v[f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]][f.ff[]]=;
q.push(f);
}
}
}
}
return ;
}
int main()
{
int F;
while(scanf("%d%d%d%d%d%d",&a[],&a[],&a[],&a[],&a[],&a[])!=EOF)
{
for(int i=; i<=; i++)
scanf("%d",&b[i]);
memset(v,,sizeof(v));
F=bfs();
if(F==) printf("-1\n");
}
return ;
}
HDU5012:Dice(bfs模板)的更多相关文章
- 2014 网选 5012 Dice(bfs模板)
/* 题意:就是给定两个筛子,每个筛子上6个面,每个面的数字属于[1,6], 且互不相同! 问a筛子最少经过按照题目规定的要求转动,达到和b筛子上下左右前后的数字相同! 思路:很直白的bfs,将每一种 ...
- POJ-2251 Dungeon Master (BFS模板题)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- BFS (1)算法模板 看是否需要分层 (2)拓扑排序——检测编译时的循环依赖 制定有依赖关系的任务的执行顺序 djkstra无非是将bfs模板中的deque修改为heapq
BFS模板,记住这5个: (1)针对树的BFS 1.1 无需分层遍历 from collections import deque def levelOrderTree(root): if not ro ...
- PAT1076. Forwards on Weibo(标准bfs模板)
//标准的层次遍历模板 //居然因为一个j写成了i,debug半天.....解题前一定要把结构和逻辑想清楚,不能着急动手,理解清楚题意,把处理流程理清楚再动手,恍恍惚惚的写出来自己慢慢debug吧 # ...
- BFS 模板
转自:欣哥 下面是bfs一般的形式,谈不上模板但一般都这么来做有点乱有什么多交流 bfs一般用于求最短时间 #include<stdio.h>#include<queue>us ...
- 图的遍历——DFS和BFS模板(一般的图)
关于图的遍历,通常有深度优先搜索(DFS)和广度优先搜索(BFS),本文结合一般的图结构(邻接矩阵和邻接表),给出两种遍历算法的模板 1.深度优先搜索(DFS) #include<iostrea ...
- POJ:Dungeon Master(三维bfs模板题)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16748 Accepted: 6522 D ...
- hdu1242 又又又是逃离迷宫(bfs模板题)
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1242/ 这次的迷宫是有守卫的,杀死一个守卫需要花费1个单位的时间,所以以走的步数为深度,在每一层进行搜索,由于走 ...
- HRBUST 1181 移动 bfs模板
#include<bits/stdc++.h>///该头文件为万能头文件,有些学校oj不能使用,读者可根据需要自行修改 using namespace std; ; int vis[MAX ...
随机推荐
- DELPHIER,正转向PYTHON了
用了10多年的DELPHI ,现在准备学PYTHON了, 理由是: 1)现在是云计算时代了,需要学习一门适应该时代的语言,研究了很久,PYTHON是最佳选择,排除了PHP,PERL,RUBY等,至于G ...
- LeetCode 26 Remove Duplicates from Sorted Array (移除有序数组中重复数字)
题目链接: https://leetcode.com/problems/remove-duplicates-from-sorted-array/?tab=Description 从有序数组中移除重 ...
- Javascript 变态题解析
读者可以先去做一下感受感受. 当初笔者的成绩是 21/44... 当初笔者做这套题的时候不仅怀疑智商, 连人生都开始怀疑了.... 不过, 对于基础知识的理解是深入编程的前提. 让我们一起来看看这些变 ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验八:PS/2模块② — 键盘与组合键
实验八:PS/2模块② — 键盘与组合键 实验七之际,我们学习如何读取PS/2键盘发送过来的通码与断码,不过实验内容也是一键按下然后释放,简单按键行为而已.然而,实验八的实验内容却是学习组合键的按键行 ...
- AD添加LOGO的方法
1 将logo图片转换成单色的BMP 图像.简单的方法是使用Windows自带的画图程序,在将图片另存为时, 在文件类型下拉列表中选择单色.bmp即可.我们以Altium为例,如图所示将蓝色logo另 ...
- 解决jenkins下使用HTML Publisher插件后查看html报告显示不正常
在jenkins后使用html publisher查看html报告时,发现显示不全,很多东西显示不了. 在查看官方文档后,这原来是安全问题所导致的. Jenkins安全默认是将以下功能都关闭了 1.j ...
- 慕课学习--OSI与TCP/IP网络协议
**OSI:开放系统互连参考模型 (Open System Interconnect 简称OSI)是国际标准化组织(ISO)和国际电报电话咨询委员会(CCITT)联合制定的开放系统互连参考模型,为开放 ...
- CentOS环境下jdk安装部署
1.准备jdk安装文件: 这里我使用的是 jdk-7u79-linux-x64.tar.gz 2.在 /usr/local 目录下创建 sotfware目录,并上传JDK文件: 解压文件并修改文件夹为 ...
- zabbix触发器表达式详解
Zabbix触发器的语法如下: {<server>:<key>.<function>(<parameter>)}<operator>< ...
- Asp.net MVC]Asp.net MVC5系列——Routing特性
目录 概述 路由特性 使用路由 可选参数和参数的默认值 路由前缀 默认路由 路由约束 自定义路由约束 路由名 区域(Area) 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列— ...