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

题目链接:点我 第一次不太清楚怎么判重,现在懂了,等下次再做 /* *HDU 4531 *BFS *注意判重 */ #include <stdio.h> #include <string.h> #include <algorithm> #include <map> #include <set> #include <string> #include <queue> #include <iostream> usin…
http://acm.hdu.edu.cn/showproblem.php?pid=1195 这道题虽然只是从四个数到四个数,但是状态很多,开始一直不知道怎么下手,关键就是如何划分这些状态,确保每一个状态都能遍历到. 得到四个数之后,分三种情况处理,每次改变一个数之后都要加入队列,最先输出的就是步数最少. #include <cstdio> #include <cstring> #include <queue> using namespace std; struct p…
Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3847    Accepted Submission(s): 1661 Problem Description Now an emergent task for you is to open a password lock. The password is co…
Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3388    Accepted Submission(s): 1499 Problem Description Now an emergent task for you is to open a password lock. The password is co…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1195 Open the Lock Description Now an emergent task for you is to open a password lock. The password is consisted of four digits. Each digit is numbered from 1 to 9. Each time, you can add or minus 1 to…
题目 猜密码,问最少操作多少次猜对,思路很简单的广搜,各种可能一个个列出来就可以了,可惜我写的很搓. 不过还是很开心,今天第一个一次过了的代码 #define _CRT_SECURE_NO_WARNINGS //这是非一般的最短路,所以广搜到的最短的路不一定是所要的路线 //所以应该把所有的路径都搜索出来,找到最短的转折数,看他是不是不大于2 //我是 用边搜索边更新当前路径的最小转弯数 来写的 #include<stdio.h> #include<string.h> #inclu…
意甲冠军:给你一个初始4数字和目标4数字,当被问及最初的目标转换为数字后,. 变换规则:每一个数字能够加1(9+1=1)或减1(1-1=9),或交换相邻的数字(最左和最右不是相邻的). 双向广搜:分别对初始和目标数字进行广搜,vis数组用1和2标记两种已搜索的数字,用mp数组记录状态的步数. 当从前往后搜能够到达2或从后往前搜能够到达1状态则就能够了... #include<stdio.h> #include<string.h> #include<string> #in…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2822 题目大意:X消耗0,.消耗1, 求起点到终点最短消耗 解题思路: 每层BFS的结点,优先级不同,应该先搜cost小的.直接退化为最短路问题. 优先队列优化. 卡输入姿势.如果O(n^2)逐个读的话会T掉.要用字符串读一行. #include "cstdio" #include "queue" #include "cstring" using…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1180 题目大意:迷宫中有一堆楼梯,楼梯横竖变化.这些楼梯在奇数时间会变成相反状态,通过楼梯会顺便到达前进方向的下一个点(跳过楼梯). 同时可以在原地等待,问到达终点的最少时间. 解题思路: 很有趣的一个题. 还是先BFS,对于一个楼梯,change函数负责计算出走楼梯能够到达的新的X和Y,再判一次是否越界或不可达. 注意,在'.'点是可以原地等待的,需要额外Push这个点,这也是这题不会出现走不出…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2531 题目大意: 你的身体占据多个点.每次移动全部的点,不能撞到障碍点,问撞到目标点块(多个点)的最少步数. 解题思路: 挺有趣的一个题,每次要移动多个点. 如果只移动一个点,就是个简单粗暴的BFS. 多个点照样处理,读图的时候把扫到的第一个点当作移动点,然后vector记录下身体的其它点与该移动点的相对坐标. BFS的时候,先看看移动点能不能动,然后再根据身体的相对坐标还原出身体的绝对坐标,看看…