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 ...
随机推荐
- JS中的内存泄漏
明天下午面试微店的前端开发职位,有点紧张~~ 刚刚正好看到js中的内存泄露,所以来整理一番. 给DOM对象添加的属性是对一个js对象的引用. var MyObject = {}; document.g ...
- .net web初级工程师教程
序 这份教程,只针对正在努力找工作的初级.net web工程师,软件这行,刚入门时找工作是个坎,希望教程对各位有帮助. 教程将通过一个实际项目,简单明了地完整呈现,在实际工作中,工程师都做些什么及怎么 ...
- c++ bitset使用
A bitset is a special container class that is designed to store bits (elements with only two possibl ...
- SSH 配置日记
1 注意struts2-spring-plugin.jar的导入. Unable to load configuration. - action 异常.需要导入这个包 2 很久都跑不通的 ...
- C++访问权限的问题
以前一直认为对于类中的private数据成员,只有调用该方法的对象才能更能访问自身的私有成员,其他的类在该成员函数(公共接口)中也无法调用自身的私有成员,今天看到<c++ prime plus& ...
- 「C」 数组、字符串、指针
一.数组 (一)数组 概念:用来存储一组数据的构造数据类型 特点:只能存放一种类型的数据,如全部是int型或者全部是char型,数组里的数据成为元素. (二)数组的定义 格式: 类型 数组名[元素个数 ...
- JavaSE学习总结第14天_API常用对象4
14.01 如何校验一个QQ号码案例 import java.util.Scanner; /* * 校验qq号码. * 1:要求必须是5-15位数字 * 2:0不能开头 * * 分析: * A:键 ...
- Laravel OAuth2 (二) ---配置与数据库设计
前言 使用 OAuth2 进行第三方登陆分为好几种情况,例如完全第三方登陆,不保存任何用户信息,或者第三方登陆后保存用户信息关联本站账号.个人觉得保存一下用户信息比较妥当(虽然这样注册的时候让用户觉得 ...
- 瀑布流的三种实现方式(原生js+jquery+css3)
前言 项目需求要弄个瀑布流的页面,用的是waterfall这个插件,感觉还是可以的,项目赶就没自己的动手写.最近闲来没事,就自己写个.大致思路理清楚,还是挺好实现的... 原生javascript版 ...
- 设计模式总结6--适配器模式 adapter pattern
适配器模式将一个类的接口,转化成客户期望的另一个接口,适配器让原本接口不兼容的类可以合作无间 public interface Sheep{ public void run(); public voi ...