Hdu1195

两个四位密码 问你最少多少步能到达

/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + ;
const int gakki = + + + + 1e9;
const int MAXN = 2e5 + , MAXM = 2e5 + ;
/*int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], ed = 1;
inline void addedge(int u, int v)
{
to[++ed] = v;
nxt[ed] = Head[u];
Head[u] = ed;
}*/
struct node
{
int now[];
int step;
} startpoint, endpoint, cnt, to;
void print(node x)
{
for (int i = ; i <= ; i++)
{
cout << x.now[i];
}
}
int finalans;
bool flag = false;
int vis[][][][];
char s[], e[];
queue<node> que[];
int stepsum[];
node get_change(node x, int aim)
{
node cur = x;
swap(cur.now[aim], cur.now[aim + ]);
return cur;
}
node get_next(node x, int aim, int y)
{
x.now[aim] += y;
if (x.now[aim] > )
{
x.now[aim] = ;
}
else if (x.now[aim] < )
{
x.now[aim] = ;
}
return x;
}
void get_vis(node x, int y)
{
vis[x.now[]][x.now[]][x.now[]][x.now[]] = y;
}
void check(node x, int y)
{
if (vis[x.now[]][x.now[]][x.now[]][x.now[]] == (y ^ ))
{
finalans = min(finalans, stepsum[] + stepsum[] + );
flag = true;
}
else if (vis[x.now[]][x.now[]][x.now[]][x.now[]] == -)
{
que[y].push(x);
get_vis(x, y);
}
}
void doit(int x)
{
while (que[x].front().step == stepsum[x] && que[x].size())
{
cnt = que[x].front();
que[x].pop();
for (int i = ; i <= ; i++)
{
if (i != )
{
to = get_change(cnt, i);
to.step = cnt.step + ;
check(to, x);
}
to = get_next(cnt, i, );
to.step = cnt.step + ;
//cout << x << " ", print(cnt), cout << " ", print(to), cout << endl;
check(to, x);
to = get_next(cnt, i, -);
to.step = cnt.step + ;
//cout << x << " ", print(cnt), cout << " ", print(to), cout << endl;
check(to, x);
}
}
stepsum[x]++;
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
flag = false;
scanf("%s", s + ), scanf("%s", e + );
stepsum[] = stepsum[] = ;
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
for (int k = ; k <= ; k++)
{
for (int w = ; w <= ; w++)
{
vis[i][j][k][w] = -;
}
}
}
}
finalans = INT_MAX;
for (int i = ; i <= ; i++)
{
while (que[i].size())
{
que[i].pop();
}
}
startpoint.step = , endpoint.step = ;
for (int i = ; i <= ; i++)
{
startpoint.now[i] = s[i] - '';
endpoint.now[i] = e[i] - '';
}
//print(startpoint), print(endpoint);
que[].push(startpoint), que[].push(endpoint);
get_vis(startpoint, ), get_vis(endpoint, );
while (!flag)
{
if (que[].size() > que[].size())
{
doit();
}
else
{
doit();
}
}
printf("%d\n", finalans);
}
return ;
}

//Hdu1195

Hdu1401

8X8的棋盘上有四个棋子 问你能不能在八步之内把一个状态转移到另一一个状态

双向BFS统计的更多相关文章

  1. POJ1915Knight Moves(单向BFS + 双向BFS)

    题目链接 单向bfs就是水题 #include <iostream> #include <cstring> #include <cstdio> #include & ...

  2. HDU 3085 Nightmare II 双向bfs 难度:2

    http://acm.hdu.edu.cn/showproblem.php?pid=3085 出的很好的双向bfs,卡时间,普通的bfs会超时 题意方面: 1. 可停留 2. ghost无视墙壁 3. ...

  3. POJ 3170 Knights of Ni (暴力,双向BFS)

    题意:一个人要从2先走到4再走到3,计算最少路径. 析:其实这个题很水的,就是要注意,在没有到4之前是不能经过3的,一点要注意.其他的就比较简单了,就是一个双向BFS,先从2搜到4,再从3到搜到4, ...

  4. [转] 搜索之双向BFS

    转自:http://www.cppblog.com/Yuan/archive/2011/02/23/140553.aspx 如果目标也已知的话,用双向BFS能很大程度上提高速度. 单向时,是 b^le ...

  5. 双向BFS

    转自“Yuan” 如果目标也已知的话,用双向BFS能很大提高速度 单向时,是 b^len的扩展. 双向的话,2*b^(len/2)  快了很多,特别是分支因子b较大时 至于实现上,网上有些做法是用两个 ...

  6. HDU 3085 Nightmare Ⅱ (双向BFS)

    Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  7. HDU 3085 Nightmare Ⅱ 双向BFS

    题意:很好理解,然后注意几点,男的可以一秒走三步,也就是三步以内的都可以,鬼可以穿墙,但是人不可以,鬼是一次走两步 分析:我刚开始男女,鬼BFS三遍,然后最后处理答案,严重超时,然后上网看题解,发现是 ...

  8. POJ 3126 Prime Path 解题报告(BFS & 双向BFS)

    题目大意:给定一个4位素数,一个目标4位素数.每次变换一位,保证变换后依然是素数,求变换到目标素数的最小步数. 解题报告:直接用最短路. 枚举1000-10000所有素数,如果素数A交换一位可以得到素 ...

  9. Hdu1401-Solitaire(双向bfs)

    Solitaire is a game played on a chessboard 8x8. The rows and columns of the chessboard are numbered ...

随机推荐

  1. ABAP Field+offset字符串截取

    *删除字符串末尾的字符 DATA:str TYPE string VALUE 'abc,defg,', sub_str TYPE string, num TYPE i. WRITE:/ str. nu ...

  2. Java:面向对象(继承,方法的重写(overide),super,object类及object类中方法的重写,父子类代码块执行顺序)

    继承: 1.继承是对某一匹类的抽象,从而实现对现实世界更好的建模. 2.提高代码的复用性. 3.extends(扩展),子类是父类的扩展. 4.子类继承父类可以得到父类的全部属性和方法.(除了父类的构 ...

  3. 问题 1014: [编程入门]阶乘求和python):(本地测试正确;但提交不对!!??)求教

    问题 1014: [编程入门]阶乘求和 时间限制: 1Sec 内存限制: 128MB 提交: 27629 解决: 5450 题目描述 求Sn=1!+2!+3!+4!+5!+…+n!之值,其中n是一个数 ...

  4. web开发常识

    web开发基本常识 服务器(硬件) 维基百科定义: 服务器作为硬件来说,通常是指那些具有较高计算能力,能够提供给多个用户使用的计算机.服务器与PC机的不同点很多,例如PC机在一个时刻通常只为一个用户服 ...

  5. 解决vmware fusion + centos 7安装vmtools时提示The path "" is not a valid path to the xxx kernel headers.

    近日使用VMware fushion 8 + centos 7.0时,无法使用共享功能,所以必须安装vmtools.但是安装过程中有2个错误需要解决. 1.gcc错误 Searching for GC ...

  6. @Value注解

    1.注入 基本字符 public class Student { @Value("qq") private String name; @Value("12") ...

  7. vue 导出JSON数据为Excel

    1. 安装三个依赖 npm install file-saver --save npm install xlsx --save npm install script-loader --save-dev ...

  8. 【神经网络与深度学习】Google Snappy - 一个高速压缩库

    Snappy已经被Google开源,作为一个压缩库,它可以利用单颗Intel Corei7处理器内核处理至少每秒250MB~500MB的数据流. Snappy的前身是Zippy.虽然只是一个数据压缩库 ...

  9. 【DSP开发】【计算机视觉】TI 视觉软件开发套件ADAS

    关键字:TI  视觉软件开发套件  ADAS 日前,德州仪器 (TI) 宣布推出其视觉软件开发套件(SDK),从而为开发人员提供了一款灵活的框架.一组丰富齐全的硬件设备驱动程序和一套适用的开发工具,可 ...

  10. DiskSim

    1.使用笔记 http://feifei432.blog.163.com/blog/static/140253361201022211949152/ http://feifei432.blog.163 ...