BFS
嘻嘻哈哈Man
这个作者很懒,什么都没留下…
展开
-
bfs-密码锁
现在一个紧急的任务是打开一个密码锁。密码由四位数字组成,每个数字从1到9进行编号。每次可以对任何一位数字加1或减1.当将9加1时,数字变为1,当1减1时,数字变为9.还可以交换相邻的数字,每一个行动记做一步。求最少步骤打开密码锁。输入格式:第一行输入四位数字,表示密码锁的初始状态第二行输入四位数字,表示开锁的密码。输出格式:输出一个整数,即最小步骤数。样例输入:12342144样...原创 2020-04-28 23:40:25 · 382 阅读 · 0 评论 -
bfs---蒜头君回家
解题思路:使用两次bfs,第一计算从起点到各点的最短距离,第二次计算终点到各点的距离,最后算出S到P+P到T的最短距离:#include<algorithm>#include<cstring>#include<iostream>#include<queue>using namespace std;typedef pair<int,...原创 2020-04-28 00:27:58 · 103 阅读 · 0 评论 -
POJ3126-首相选门牌
题目:http://poj.org/problem?id=3126The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on thei...转载 2019-11-24 21:57:32 · 68 阅读 · 0 评论