/*
    Name: HDU--1195--Open the Lock
    Author: shen_渊
    Date: 17/04/17 08:54
    Description: bfs,用四维数组标记状态,每位数字可以做三种操作 +1,-1,交换
                可以不用优先队列,题意决定,优先队列更费时间
*/

#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
struct node{
    int steps;
    string s;
    node():steps(){
    };
    bool operator <(const node &a)const{
        return steps>a.steps;
    }
};
int bfs();
][][][];
string str1,str2;
int main()
{
    ios::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);
    int n;cin>>n;
    while(n--){
        memset(vis,,sizeof(vis));
        cin>>str1>>str2;
        if(str1 == str2)cout<<"0\n";
        else cout<<bfs()<<endl;
    }
    ;
}
int bfs(){
    priority_queue<node> q;
    node p;
    p.s = str1;
    q.push(p);
    vis[p.s[]-]-]-]-;
    while(!q.empty()){
        node a,temp;
        temp = q.top();q.pop();
        if(temp.s == str2)return temp.steps;
        ; i<; ++i) {
            //+1
            a.s = temp.s;
            ';
            ;
            ]-]-]-]-']){
                a.steps = temp.steps + ;
                q.push(a);
                vis[a.s[]-]-]-]-;
            }
            //-1
            a.s = temp.s;
            ';
            ;
            ]-]-]-]-']){
                a.steps = temp.steps + ;
                q.push(a);
                vis[a.s[]-]-]-]-;
            }
            //交换
            ){
                a.s = temp.s;
                a.s[i] = temp.s[i+];
                a.s[i+] = temp.s[i];
                ]-]-]-]-']){
                a.steps = temp.steps + ;
                q.push(a);
                vis[a.s[]-]-]-]-;
                }
            }
        }
    }
    ;
}

HDU--1195--bfs--Open the Lock的更多相关文章

  1. hdu 4531 bfs(略难)

    题目链接:点我 第一次不太清楚怎么判重,现在懂了,等下次再做 /* *HDU 4531 *BFS *注意判重 */ #include <stdio.h> #include <stri ...

  2. hdu - 1195 Open the Lock (bfs) && hdu 1973 Prime Path (bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1195 这道题虽然只是从四个数到四个数,但是状态很多,开始一直不知道怎么下手,关键就是如何划分这些状态,确保每一个 ...

  3. hdu 1195:Open the Lock(暴力BFS广搜)

    Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. hdu 1195 Open the Lock (BFS)

    Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. hdu 1195 Open the Lock

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1195 Open the Lock Description Now an emergent task f ...

  6. hdu 1195 Open the Lock(广搜,简单)

    题目 猜密码,问最少操作多少次猜对,思路很简单的广搜,各种可能一个个列出来就可以了,可惜我写的很搓. 不过还是很开心,今天第一个一次过了的代码 #define _CRT_SECURE_NO_WARNI ...

  7. HDU 1195 Open the Lock (双宽搜索)

    意甲冠军:给你一个初始4数字和目标4数字,当被问及最初的目标转换为数字后,. 变换规则:每一个数字能够加1(9+1=1)或减1(1-1=9),或交换相邻的数字(最左和最右不是相邻的). 双向广搜:分别 ...

  8. HDU 2822 (BFS+优先队列)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2822 题目大意:X消耗0,.消耗1, 求起点到终点最短消耗 解题思路: 每层BFS的结点,优先级不同 ...

  9. HDU 1180 (BFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1180 题目大意:迷宫中有一堆楼梯,楼梯横竖变化.这些楼梯在奇数时间会变成相反状态,通过楼梯会顺便到达 ...

  10. HDU 2531 (BFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2531 题目大意: 你的身体占据多个点.每次移动全部的点,不能撞到障碍点,问撞到目标点块(多个点)的最 ...

随机推荐

  1. mysql的my.ini文件详解

    mysql数据库在配置时包含很多信息:端口号,字符编码,指定根路径 basedir,指定数据存放的路径等信息 mysql的字体编码分为两种: 服务器编码 客户端输入的编码 通常服务器的编码都是utf- ...

  2. 国内互联网公司github网址

    -----------------------------------------------------推荐技术------------------------------------------- ...

  3. http请求的完整过程

    HTTP通信机制是在一次完整的HTTP通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: 1. 建立TCP连接 在HTTP工作开始之前,Web浏览器首先要通过网络与Web服务器建立连接,该 ...

  4. 查看表结构命令(mysql和oracle)

    MySQL查看表结构SQL语句 = mysql查看表结构命令,如下: desc 表名; show columns from 表名; describe 表名; show create table 表名; ...

  5. jq-animate实现返回顶部效果

    jq-animate实现返回顶部效果: <!doctype html> <html lang="en"> <head> <meta cha ...

  6. “HK”的日常之ARP断网攻击

    ARP断网攻击是什么?可以吃吗?如果可以吃它好吃吗? ARP断网攻击就是通过伪造IP地址和MAC地址实现ARP欺骗,能够在网络中产生大量的ARP通信量使网络阻塞,攻击者只要持续不断的发出伪造的ARP响 ...

  7. selenium 环境搭建

    使用selenium + python来搭建环境的步骤: 1. 下载 python 的版本,常用到的有 2.7 和 3.6 2. 下载 selenium 的版本,通过命令进行下载. pip insta ...

  8. Ext template 的使用

    Ext template 的使用 Ext.define('app.view.MyDataView', { extend: 'Ext.panel.Panel', xtype: 'myDataView', ...

  9. SQL执行过程中的性能负载点

    一.SQL执行过程 1.用户连接数据库,执行SQL语句: 2.先在内存进行内存读,找到了所需数据就直接交给用户工作空间: 3.内存读失败,也就说在内存中没找到支持SQL所需数据,就进行物理读,也就是到 ...

  10. Unity3D 物体移动到指定点

    transform.position=Vector3.MoveTowards(transform.position , Target.position, speed * Time.deltaTime) ...