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 题目大意: 你的身体占据多个点.每次移动全部的点,不能撞到障碍点,问撞到目标点块(多个点)的最 ...
随机推荐
- 验证表格多行某一input是否为空
function checkTableKeyWordVal(tableId){ var result = true; $("#"+tableId+" tbody tr&q ...
- javascript四舍五入tofixed
//toFixed() 方法可把 Number 四舍五入为指定小数位数的数字. $("#renjunlirun").val(zongLiRun.toFixed(2));//金额
- java语言中的匿名类与lambda表达式介绍与总结 (Anonymous Classes and Lambda Expressions)
2017/6/30 转载写明出处:http://www.cnblogs.com/daren-lin/p/anonymous-classes-and-lambda-expressions-in-java ...
- 2017寒假零基础学习Python系列之函数之 定义默认参数
在定义函数时,可以有默认参数例如Python自带的函数int(),其实就是两个参数,我们既可以传一个参数,又可以传两个参数 int(') >>>123 int(',8) 83 int ...
- poj 1948 Triangular Pastures 小结
Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The o ...
- CSS3集锦之新增选择器、圆角、阴影、透明度、transition动画、transform变形、animation动画
---恢复内容开始--- 一.CSS3新增选择器 1.nth-chlid(n)用法 selector:nth-chlid(n)指找到第n个子元素并且该元素为selector标签 <!DOCTYP ...
- MySQL缓存之Qcache与buffer pool对比
Q:innodb buffer pool和Qcache的缓存区别? A: 1.Qcacche缓存的是SQL语句及对应的结果集,缓存在内存,最简单的情况是SQL一直不重复,那Qcache的命令率肯定是0 ...
- python编程快速上手之第9章实践项目参考答案
本章介介绍了shutil,zipfile模块的使用,我们先来认识一下这2个模块吧. 一.shutil模块 shutil模块主要用于对文件或文件夹进行处理,包括:复制,移动,改名和删除文件,在shuti ...
- Go学习笔记(一)Let's 干
加 Golang学习 QQ群共同学习进步成家立业 ^-^ 群号:96933959 简介 Go是Google开发的一种 静态强类型.编译型,并发型,并具有垃圾回收功能的编程语言.为了方便搜索和识 ...
- Jenkins迁移job
说明:从一个Jenkins服务器A将现有job迁移到另外一个Jenkins服务器B. 方法:You can copy or move build jobs between instances of p ...