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 ...
随机推荐
- 关于yield创建协程的理解
先上利于理解的代码: #coding:utf-8 def consumer(): c_r = '' while 1: m = yield c_r if not m: return print(&quo ...
- 使用RUBY生成二维码
二维码现在貌似已经成为一个项目必不可少的总分了,最近在做的微信项目,更是大大的依赖于二维码,微信公众平台提供的临时二维码,局限太多,只能带一个ID,做不了太多有意义的整个,因为我们很多的二维码是需要自 ...
- 帝国cms灵动标签下常用标签
这里简单整理下灵动标签下的常用标签 标题名称:<?=$bqr['title']?> <?=esub($bqr[title],22)?> 限制字符22个 标题链接:<?= ...
- Qt在Linux环境下应用程序字体模糊的解决方法(先改成使用默认字体,然后使用qtconfig配置)
这两天一直在用Qt实现一个跨平台的软件.软件之前在Windows上编写的,后来放到里Ubuntu 10.10下编译.程序运行时遇到一个很棘手的问题,界面文本非常模糊.后来在网上查阅了好几天的资料,经历 ...
- 将dll放进exe[.Net]
原文:将dll放进exe[.Net] 两种方案: 1.使用ILMerge工具. 缺点:需离开工程,使用第三方工具(ILMerge). 2.将dll作为Resource放进exe,exe执行时动态加载( ...
- Json.Net系列教程 4.Linq To JSON
原文 Json.Net系列教程 4.Linq To JSON 更改历史 2013-05-31 添加一个FAQ 一.Linq to JSON是用来干什么的? Linq to JSON是用来操作JSO ...
- 快速注册Uber司机,兼职月入轻松过万
Uber是世界领先的即时用车网络平台.当前部分中国城市,Uber司机只需每周完成70单,可获得7000元的激励制度回报司机,月收入近3万元.[加入条件]1. 车辆为本地牌照2. 车龄在5年以内3. 裸 ...
- out/target/common/obj/PACKAGING/public_api.txt android.view.KeyEvent.KEYCODE_has changed value from
编译出错: out/target/common/obj/PACKAGING/public_api.txt:22549: error 17: Field android.view.KeyEvent.KE ...
- 基于RYU控制器(controller)上的simple-switch 的APP做的測试-SDN/OpenFlow
近期一直在学习RYU控制器,在使用的过程中,发现有下面几方面的长处:RYU控制器全然使用Python语言编写,在理解起来和上手速度上是挺快的:RYU控制器的总体架构清晰明了,在日后有时间我会整理一个关 ...
- VPN连接在遇到飞鱼星设备时可能出现的疑难问题
在连接VPN设备时,设置都是正常的.在