简单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的更多相关文章

  1. HDU 5012 Dice (BFS)

    事实上是非常水的一道bfs,用字符串表示每一个状态,map判重就ok了. 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5012 #include&l ...

  2. hdu 5012 Dice

    Problem Description There are 2 special dices on the table. On each face of the dice, a distinct num ...

  3. 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 ...

  4. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  5. HDU 5012 骰子旋转(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 保存骰子的状态,然后用dfs或者bfs搜索 还是再讲一下dfs 我们的目标是找一个与b相同,且转次数最少的 ...

  6. Spring-1-F Dice(HDU 5012)解题报告及测试数据

    Dice Time Limit:1000MS     Memory Limit:65536KB Description There are 2 special dices on the table. ...

  7. hdu 5012 模拟+bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...

  8. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

  9. hdu 4499 Cannon dfs

    Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...

随机推荐

  1. 0610 python 基础03

    复习: 条件判断 if..else >>> age=28 >>> if age<18: ...   print "你还没有成年吧" ... ...

  2. [LeetCode]题解(python):069-Sqrt(x)

    题目来源: https://leetcode.com/problems/sqrtx/ 题意分析: 实现一个整型的开根. 题目思路: 利用牛顿迭代法可以求解.首先讲数据类型转成浮点数,然后选取初始值为n ...

  3. 07-C语言流程控制if、switch

    目录: 一.流程控制 条件分支 if else 二.流程控制 开关分支 switch 回到顶部 一.流程控制 条件分支 1.语法格式:if(表达式1){ //表达式1为真(非0时),执行的语句部分. ...

  4. IOS 使用程序外地图(IOS Map and google Map)

    1.调用IOS6苹果地图 IOS6中实现这个功能需要使用Map Kit中的MKPlaceMark和MKMapItem两个类,因此我们需要在工程中添加MapKit.framework主要代码如下: - ...

  5. 代码收藏 JS实现页内查找定位功能

    前部分为IE下搜索方法 用TextRange来实现 后部分为firefox.chrome下搜索方法 var nextIndex = 0; var searchValue = ''; var input ...

  6. 在windows系统中安装hadoop

    1.安装Cygwin 从http://www.cygwin.com/ 下载cygwin的setup.exe,双击运行: 选择从Internet安装: 设置安装目录: 设置安装包目录: 设置“Inter ...

  7. 用Html5结合Qt制作一款本地化EXE游戏-太空大战(Space War)

    本次来说一说如何利用lufylegend.js引擎制作一款html5游戏后将其通过Qt转换成EXE程序.步骤其实非常简单,接下来就一步步地做一下解释和说明. 首先我们来开发一个有点类似于太空大战的游戏 ...

  8. Foundation Sorting: Single List Insertion Sort

    /* List Insertion Sorting. * Implementation history:. * 2013-09-15, Mars Fu, first version. */ #incl ...

  9. Java代码优化策略

    1.生成对象时,合理分配空间和大小:new ArrayList(100); 2.优化for循环: Vector vect = new Vector(1000); For(int i=0; i<v ...

  10. vmware能够ping通内网,上不了外网的解决方法

    一般这是由于里面的路由域名服务器没有配置好. issta@ubuntu:~$ ping www.baidu.com ping: unknown host www.baidu.com 先看一下地址解析器 ...