Description
The cornfield maze is a popular Halloween treat.Visitors are shown the entrance and must wander through the mazefacing zombies, chainsaw-wielding psychopaths, hippies, and otherterrors on their quest to find the exit.
One popular maze-walking strategy guarantees that the visitor willeventually find the exit. Simply choose either the right or leftwall, and follow it. Of course, there's no guarantee which strategy(left or right) will be better, and the path taken is seldom themost efficient. (It also doesn't work on mazes with exits that arenot on the edge; those types of mazes are not represented in thisproblem.)
As the proprieter of a cornfield that is about to be converted intoa maze, you'd like to have a computer program that can determinethe left and right-hand paths along with the shortest path so thatyou can figure out which layout has the best chance of confoundingvisitors.
One popular maze-walking strategy guarantees that the visitor willeventually find the exit. Simply choose either the right or leftwall, and follow it. Of course, there's no guarantee which strategy(left or right) will be better, and the path taken is seldom themost efficient. (It also doesn't work on mazes with exits that arenot on the edge; those types of mazes are not represented in thisproblem.)
As the proprieter of a cornfield that is about to be converted intoa maze, you'd like to have a computer program that can determinethe left and right-hand paths along with the shortest path so thatyou can figure out which layout has the best chance of confoundingvisitors.
Input
Input to this problem will begin with a linecontaining a single integer n indicating the number of mazes. Eachmaze will consist of one line with a width, w, and height, h (3<= w, h <= 40), followed by h lines of w characters each thatrepresent the maze layout.
Walls are represented by hash marks('#'), empty space by periods ('.'), the start by an 'S' and theexit by an 'E'.
Exactly one 'S' and one 'E' will be present in the maze, and theywill always be located along one of the maze edges and never in acorner. The maze will be fully enclosed by walls ('#'), with theonly openings being the 'S' and 'E'. The 'S' and 'E' will also beseparated by at least one wall ('#').
You may assume that the maze exit is always reachable from thestart point.
Exactly one 'S' and one 'E' will be present in the maze, and theywill always be located along one of the maze edges and never in acorner. The maze will be fully enclosed by walls ('#'), with theonly openings being the 'S' and 'E'. The 'S' and 'E' will also beseparated by at least one wall ('#').
You may assume that the maze exit is always reachable from thestart point.
Output
For each maze in the input, output on a singleline the number of (not necessarily unique) squares that a personwould visit (including the 'S' and 'E') for (in order) the left,right, and shortest paths, separated by a single space each.Movement from one square
to another is only allowed in thehorizontal or vertical direction; movement along the diagonals isnot allowed.
Sample Input
2
8 8
########
#......#
#.####.#
#.####.#
#.####.#
#.####.#
#...#..#
#S#E####
9 5
#########
#.#.#.#.#
S.......E
#.#.#.#.#
#########
Sample Output
37 5 5
17 17 9
这个题..呵呵....
第一次做了深搜.恩= =
求最小步数用广搜.这个没什么好说的了.就是在于深搜求左边路线与右边路线的问题.深搜时候,重点是要确立方向.
用一个变量dl记录上一次朝向的方向.比如上一次是向上走的,那么这一次应该向左,向上,向右,向下.用1,2,3,4表示左上右下.右深搜也一样.
还需要注意的一点就是不用标记.因为走过的路可以再走.
#include
#include
using namespace std;
char a[43][43], vis[43][43];
int dirx[4] = {-1,0,1,0}, diry[4] = {0, 1, 0, -1}, mi, dl, dr,lp, f1, rp, f2;
typedef struct node
{
}node;
void dfsl(int x, int y, int dl)
{
}
void dfsr(int x, int y, int dr)
{
}
int bfs(int x, int y)
{
}
int main()
{
}