HDU3085NightmareII题解--双向BFS】的更多相关文章

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3085 分析 大意就是一个男孩和一个女孩在网格里,同时还有两个鬼,男孩每轮走三步,女孩每轮走一步,与鬼曼哈顿距离不超过2*轮数的区域都被鬼占领,问男孩女孩最少多少轮相遇? 这题显然用双向BFS,男孩每轮拓展3次,女孩每轮拓展1次,一个记录女孩走过哪些地方,另一个记录男孩,有个地方被两人都走过就输出答案 然后一开始我就发现我的BFS写得代码又臭又长,后面看一位大佬博客才学到简洁的操作 代码 #inclu…
Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3012    Accepted Submission(s): 856 Problem Description Last night, little erriyue had a horrible nightmare. He dreamed that he and h…
思路: 最大步骤有20,直接BFS会超时. 因为知道开始情况和结果所以可以用双向BFS,每个BFS规定最大步骤为10,这样相加肯定小于20.这里要保存每个状态搜索到的最小步骤,用Hash储存.当发现现有状态已经在另一路出现了,那么就输出两者相加的步骤和. 代码: #include<iostream> #include<algorithm> #include<queue> #include<map> #define ll long long using nam…
发现直接搜索比较麻烦,但是要同时两个人一起走容易想到双向bfs,比较普通, 在判断是否碰到ghost时只要比较两点的曼哈顿距离大小和step*2(即ghost扩散的距离)即可,仔细思考也是可以想到的 #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<algorithm> using namespace std; ; struct node{…
题意:很好理解,然后注意几点,男的可以一秒走三步,也就是三步以内的都可以,鬼可以穿墙,但是人不可以,鬼是一次走两步 分析:我刚开始男女,鬼BFS三遍,然后最后处理答案,严重超时,然后上网看题解,发现是双向BFS 就一秒一秒走就行,男的一秒走3,女的一秒走1,然后走过的分别赋值男女标记,当走到对方的标记时就是答案了 然后有一个不能走的地方和两个鬼的位置曼哈顿距离搞一下就行, 注:然后涨了姿势,是队列可以直接赋值,q1=q2,以前都不知道 #include<cstdio> #include<…
Problem UVA1601-The Morning after Halloween Accept: 289 Submit: 3136 Time Limit: 12000 mSec  Problem Description  Input  Output For each dataset in the input, one line containing the smallest number of steps to restore ghosts into the positions where…
题目描述 给你一张 $n$ 个点 $m$ 条边的随机图,边权为1.$k$ 次询问两点间最短路,不连通则输出-1. 输入 第一行包含3个正整数n,m,k(2<=n<=100000,1<=m<=300000,1<=k<=10000),分别表示点数.边数和询问数. 接下来m行,每行两个正整数u_i,v_i(1<=u_i,v_i<=n),表示一条双向道路.输入数据保证不会有重边和自环. 接下来k行,每行两个正整数u_i,v_i(1<=u_i,v_i<=n…
Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6016    Accepted Submission(s): 2680 Problem Description Now an emergent task for you is to open a password lock. The password is c…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3085 Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2790    Accepted Submission(s): 781 Problem Description Last night, little erriyu…
Barareh on Fire Submit Page Description The Barareh village is on fire due to the attack of the virtual enemy. Several places are already on fire and the fire is spreading fast to other places. Khorzookhan who is the only person remaining alive in th…