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…
Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 886 Accepted Submission(s): 185 Problem Description Last night, little erriyue had a horrible nightmare. He dreamed that he and hi…
Solitaire is a game played on a chessboard 8x8. The rows and columns of the chessboard are numbered from 1 to 8, from the top to the bottom and from left to right respectively.There are four identical pieces on the board. In one move it is allowed to…
The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile missing. Let's…
对于搜索树分支很多且有明确起点和终点的情况时,可以采用双向搜索来减小搜索树的大小. 对于双向BFS来说,与单向最大的不同是双向BFS需要按层扩展,表示可能到达的区域.而单向BFS则是按照单个节点进行扩展,因为只有当前状态. 代码如下: #include <bits/stdc++.h> using namespace std; const int maxn=810; char mp[maxn][maxn]; int n,m,tot,step,f; struct node{ int x,y; }b…
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…
Description Let's play a puzzle using eight cubes placed on a 3 × 3 board leaving one empty square. Faces of cubes are painted with three colors. As a puzzle step, you can roll one of the cubes to a adjacent empty square. Your goal is to make the spe…