HDU 5012 Dice DFS
简单DFS
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
using namespace std; const int INF = 0x3f3f3f3f;
const int MAXN = ;
const double eps = 1e-; int a[];
int b[];
bool ans;
int cnt; void lleft(){
int temp_a1 = a[];
int temp_a2 = a[];
int temp_a3 = a[];
int temp_a4 = a[];
a[] = temp_a4;
a[] = temp_a3;
a[] = temp_a1;
a[] = temp_a2;
} void rright(){
int temp_a1 = a[];
int temp_a2 = a[];
int temp_a3 = a[];
int temp_a4 = a[];
a[] = temp_a3;
a[] = temp_a4;
a[] = temp_a2;
a[] = temp_a1;
} void ffront(){
int temp_a1 = a[];
int temp_a2 = a[];
int temp_a5 = a[];
int temp_a6 = a[];
a[] = temp_a6;
a[] = temp_a5;
a[] = temp_a1;
a[] = temp_a2;
} void bback(){
int temp_a1 = a[];
int temp_a2 = a[];
int temp_a5 = a[];
int temp_a6 = a[];
a[] = temp_a5;
a[] = temp_a6;
a[] = temp_a2;
a[] = temp_a1;
} bool same(){
if(a[] == b[] && a[] == b[] && a[] == b[] && a[] == b[] && a[] == b[] && a[] == b[])
return true;
return false;
} void dfs(int count){
if(count > ){
return;
}
if(same()){
if(count < cnt){
cnt = count;
}
return;
} int a1 = a[];
int a2 = a[];
int a3 = a[];
int a4 = a[];
int a5 = a[];
int a6 = a[]; lleft();
dfs(count + );
a[] = a1;
a[] = a2;
a[] = a3;
a[] = a4;
a[] = a5;
a[] = a6;
rright();
dfs(count + );
a[] = a1;
a[] = a2;
a[] = a3;
a[] = a4;
a[] = a5;
a[] = a6;
ffront();
dfs(count + );
a[] = a1;
a[] = a2;
a[] = a3;
a[] = a4;
a[] = a5;
a[] = a6;
bback();
dfs(count + );
} int main(){
int i, j, t, n, m, k;
while(EOF != scanf("%d%d%d%d%d%d",&a[],&a[],&a[],&a[],&a[],&a[])){
scanf("%d%d%d%d%d%d",&b[],&b[],&b[],&b[],&b[],&b[]);
cnt = INF;
ans = false;
dfs();
if(cnt != INF)
printf("%d\n",cnt);
else
printf("-1\n");
}
return ;
}
HDU 5012 Dice DFS的更多相关文章
- HDU 5012 Dice (BFS)
事实上是非常水的一道bfs,用字符串表示每一个状态,map判重就ok了. 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5012 #include&l ...
- hdu 5012 Dice
Problem Description There are 2 special dices on the table. On each face of the dice, a distinct num ...
- 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.5692 Snacks ( DFS序 线段树维护最大值 )
HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...
- HDU 5012 骰子旋转(DFS)
http://acm.hdu.edu.cn/showproblem.php?pid=5012 保存骰子的状态,然后用dfs或者bfs搜索 还是再讲一下dfs 我们的目标是找一个与b相同,且转次数最少的 ...
- Spring-1-F Dice(HDU 5012)解题报告及测试数据
Dice Time Limit:1000MS Memory Limit:65536KB Description There are 2 special dices on the table. ...
- hdu 5012 模拟+bfs
http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...
- hdu 5727 Necklace dfs+二分图匹配
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
- hdu 4499 Cannon dfs
Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...
随机推荐
- linux里source、sh、bash、./有什么区别
在linux里,source.sh.bash../都可以执行shell script文件,那它们有什么不同吗? ----------- 1.source source a.sh 在当前shell内去读 ...
- R语言学习之主成分分析法的R实践
主成分分析R软件实现程序(一): >d=read.table("clipboard",header=T) #从剪贴板读取数据 >sd=scale(d) #对数据进行标 ...
- 什么是core dump?(转)
什么是Core Dump? 今天调试一个程序, 用到了core dump, 于是写出来, 记于此.什么是Core Dump?Core的意思是内存, Dump的意思是扔出来, 堆出来.开 发和使用Uni ...
- IM与工作信息流整合
IM与工作信息流整合,希望减轻用户“信息”负担 从36氪此前的<“明道”现在推出个人免费版本,是怎样的逻辑?>一 文中,我们可以了解到,国内现在的协作产品设计思路主要有两种:一种是像t ...
- wordpress模板制作第一课
一套完整的WordPress模板应至少具有如下文件: style.css : CSS(样式表)文件 index.php : 主页模板 archive.php : Archive/Category模板 ...
- IIs 网站应用程序与虚拟目录的区别及高级应用说明(文件分布式存储方案)
原文 IIs 网站应用程序与虚拟目录的区别及高级应用说明(文件分布式存储方案) 对于IIS网站,大伙用的比较多,就不啰嗦了. 今天和说说大伙比较少使用的"IIS应用程序”和虚拟目录的区别 ...
- mysql读写分离
严格意义上讲,MySQL 读.写分离确实存在上述情况,这是由Master-Slave 异步复制存在延迟所导致的,且Master binlog的写入为多线程,而Slave同步的sql_thread为单线 ...
- BeanFactory 和ApplicationContext
BeanFactory和ApplicationContext对待bean后置处理器稍有不同.ApplicationContext会自动检测在配置文件中实现了BeanPostProcessor接口的所有 ...
- mac下的搭建本地discuz论坛
本地是php+mysql+apache的环境.也可以用xampp一键安装的东西,那个貌似比较省事.因为我的本地php环境已经装好了,就直接下了discuz的代码安装. 打开web共享 将discuz代 ...
- 自己定义View----点击滑动选择字母列表
因为项目须要,也不想使用网上的写好的控件,于是作死的自己定义了一个控件.特此记录下成功.效果例如以下: 首先须要把全部的字母绘制出来: private static String letters[] ...