HDU--1195--bfs--Open the Lock
/*
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的更多相关文章
- hdu 4531 bfs(略难)
题目链接:点我 第一次不太清楚怎么判重,现在懂了,等下次再做 /* *HDU 4531 *BFS *注意判重 */ #include <stdio.h> #include <stri ...
- hdu - 1195 Open the Lock (bfs) && hdu 1973 Prime Path (bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1195 这道题虽然只是从四个数到四个数,但是状态很多,开始一直不知道怎么下手,关键就是如何划分这些状态,确保每一个 ...
- hdu 1195:Open the Lock(暴力BFS广搜)
Open the Lock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1195 Open the Lock (BFS)
Open the Lock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1195 Open the Lock
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1195 Open the Lock Description Now an emergent task f ...
- hdu 1195 Open the Lock(广搜,简单)
题目 猜密码,问最少操作多少次猜对,思路很简单的广搜,各种可能一个个列出来就可以了,可惜我写的很搓. 不过还是很开心,今天第一个一次过了的代码 #define _CRT_SECURE_NO_WARNI ...
- HDU 1195 Open the Lock (双宽搜索)
意甲冠军:给你一个初始4数字和目标4数字,当被问及最初的目标转换为数字后,. 变换规则:每一个数字能够加1(9+1=1)或减1(1-1=9),或交换相邻的数字(最左和最右不是相邻的). 双向广搜:分别 ...
- HDU 2822 (BFS+优先队列)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2822 题目大意:X消耗0,.消耗1, 求起点到终点最短消耗 解题思路: 每层BFS的结点,优先级不同 ...
- HDU 1180 (BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1180 题目大意:迷宫中有一堆楼梯,楼梯横竖变化.这些楼梯在奇数时间会变成相反状态,通过楼梯会顺便到达 ...
- HDU 2531 (BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2531 题目大意: 你的身体占据多个点.每次移动全部的点,不能撞到障碍点,问撞到目标点块(多个点)的最 ...
随机推荐
- loadrunner 手工参数拼接与l oadrunner的url编码
Acction() { //演示需要的一些变量,提前声明 char *name = "yezi_zh"; "; char *work = "engin" ...
- jquery提交form表单插件jquery.form.js
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 如何设计相对安全的cookie自动登录系统
很多网站登录的时候,都会有一个"记住我"功能,用户可以在限定时间段内免登录, 比如豆瓣.人人.新浪微博等都有这种设计.这种技术其实就是基于 cookie的自动登录, 用户登录的时候 ...
- 解决yii框架,gii脚手架不能使用。
应用场景 把代码转移到线上服务器时,GII.BUG工具不正常使用,但在本地服务器是正常的. 分析原因 Yii框架在使用GII 和BUG 时,会针对访问IP地址拦截,没有在配置中设置的IP地址是会默认被 ...
- Ajax 向后台提交一个 JavaScript 对象数组?
var postArray= new Array(); var temp = new Object(); temp.id='1'; temp.name='test'; postArray.push(t ...
- 怎样把echarts图表做成响应式的
如果想要把echarts图表给做成响应式的那么就应该用rem 单位,给图表的外围容器设置rem 单位,然后调用jquery 的resize方法,$(window).resize(function(){ ...
- Java数据类型在实际开发中的应用二枚举类型
在实际编程中,往往存在着这样的"数据集",它们的数值在程序中是稳定的,而且"数据集"中的元素是有限的.在JDK1.5之前,人们用接口来描述这一种数据类型. 1. ...
- 5个为什么(five-whys)
文章非常好,我认为我们必须实施这一思想. 原文:http://venturehacks.com/articles/five-whys 翻译:http://www.tuicool.com/article ...
- vue的增删改查
我们把这些用户信息保存到list的数组中,然后增删改查就在这个数组上进行: list: [ { username: 'aaaaa', email: '123@qq.com', sex: '男', pr ...
- win7下elasticsearch5.0 安装head插件
项目开发用到了ES,5.X版本的,然而网上好多的安装资料都不能用,全是之前的老版本,今天弄了一上午终于完事了,总结一下安装的步骤. 1.安装NodeJs 去官网https://nodejs.org/e ...