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 ...
随机推荐
- poj 3358
/** 大意: 给定小数(p/q),求其循环节的大小和循环节开始的位置 解法: 若出现循环 ai*2^m= aj%p; 即 2^m %p =1 若2与p 互素,则可由欧拉函数的, 不互素,需将其转化为 ...
- JVM报错提示
持久代被占满 异常:java.lang.OutOfMemoryError: PermGen space 说明: Perm空间被占满.无法为新的class分配存储空间而引发的异常.这个异常以前是没有的, ...
- 前端笔试题 JS部分
题目 http://www.itmian4.com/forum.php?mod=viewthread&tid=4540 http://www.itmian4.com/forum.php?mod ...
- oracle10g安装图解(win7)
一.Oracle10g 安装预备步骤取得 Oracle 10g 安装程序,或从 Oracle 技术网(OTN)下载光盘映像.在评估阶段您可以免费下载和使用无技术限制的全功能 Oracle,但在正式的商 ...
- shouldOverrideUrlLoading相关说明
给WebView加一个事件监听对象(WebViewClient)并重写其中的一些方法:shouldOverrideUrlLoading:对网页中超链接按钮的响应.当按下某个连接时WebViewClie ...
- 在Spring Boot启动后执行指定代码
在开发时有时候需要在整个应用开始运行时执行一些特定代码,比如初始化环境,准备测试数据等等. 在Spring中可以通过ApplicationListener来实现相关的功能,不过在配合Spring Bo ...
- tomcat的webappclassloader中一个奇怪的异常信息
假设一个应用抛出大量的Class not found信息,一般你会怀疑包冲突.但是tomcat的webappclassloader却有这种问题: 假设一个应用公布出现故障, webappclasslo ...
- linux内核源码阅读之facebook硬盘加速利器flashcache
从来没有写过源码阅读,这种感觉越来越强烈,虽然劣于文笔,但还是下定决心认真写一回. 源代码下载请参见上一篇flashcache之我见 http://blog.csdn.net/liumangxiong ...
- leetCode 24. Swap Nodes in Pairs (双数交换节点) 解题思路和方法
Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For exa ...
- 【从0開始Tornado建站】群聊
群聊的前台主要代码: {%block content%} <!--<p class='text-success h3'>測试版本号,每天凌晨4:00清水,enjoy it~~:-)& ...