English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

A maze is a two dimensional structure with an entrance and sometimes an exit. The job for this program is to determine if the given maze has an exit. All of the mazes will have the entrance point at the top left corner. The exit point can be anywhere in the far right column. A valid path will be a continuous block of 1s that connect the top left corner to any spot on the far right column. A valid path can only be connected horizontally or vertically. Diagonal connections are not legal. The 1s in the file represent the path and 0s represent the walls of the maze. Output EXIT FOUND if there is a path leading to an exit out of the maze. Output NO EXIT FOUND if there is not a path leading out of the maze.

Helpful Hints / Assumptions: All input will be 1s and 0s. The 1s represent the path and 0s show that there is no path in that area.
Sample Data :
5
1 0 0 0 1
1 1 1 1 0
0 0 1 0 1
0 1 1 1 0
0 0 0 0 1
7
1 0 0 0 0 1 1
1 1 1 1 0 1 0
0 0 1 0 0 1 0
0 1 1 1 0 1 0
0 1 0 1 0 1 0
0 1 0 1 1 1 0
0 1 0 1 0 0 1
7
1 0 0 0 0 1 0
1 1 1 1 0 1 0
0 0 1 0 0 1 0
0 1 1 1 0 1 0
0 1 0 1 0 1 0
0 1 0 1 1 1 0
0 1 0 1 0 1 0
7
1 0 1 1 0 1 0
1 1 1 1 1 1 0
0 0 1 0 0 0 1
0 1 1 1 1 1 1
0 1 0 1 0 1 0
1 1 1 1 1 1 0
0 1 0 1 0 1 0
10
1 0 1 1 0 1 0 1 1 1
1 1 1 1 1 1 0 1 0 1
0 0 1 0 0 0 1 1 1 1
0 1 1 1 1 1 1 1 0 1
0 1 0 1 0 1 0 1 0 1
1 1 1 1 1 1 0 1 1 1
0 1 0 1 0 1 0 0 0 1
0 1 1 1 0 1 0 0 0 0
0 1 0 1 0 1 0 1 1 1
0 1 1 1 1 1 0 1 1 1
10
1 0 1 1 0 1 1 1 1 0
1 1 1 1 1 1 0 1 0 1
0 0 1 0 0 0 1 1 1 0
0 1 1 1 1 1 1 1 0 1
0 1 0 1 0 1 0 1 0 1
1 1 1 1 1 1 0 1 1 0
0 1 0 1 0 1 0 0 0 0
0 1 1 1 0 1 0 0 1 1

Sample Output :
1 0 0 0 1
1 1 1 1 0
0 0 1 0 1
0 1 1 1 0
0 0 0 0 1
exit not found

1 0 0 0 0 1 1
1 1 1 1 0 1 0
0 0 1 0 0 1 0
0 1 1 1 0 1 0
0 1 0 1 0 1 0
0 1 0 1 1 1 0
0 1 0 1 0 0 1
exit found

1 0 0 0 0 1 0
1 1 1 1 0 1 0
0 0 1 0 0 1 0
0 1 1 1 0 1 0
0 1 0 1 0 1 0
0 1 0 1 1 1 0
0 1 0 1 0 1 0
exit not found

1 0 1 1 0 1 0
1 1 1 1 1 1 0
0 0 1 0 0 0 1
0 1 1 1 1 1 1
0 1 0 1 0 1 0
1 1 1 1 1 1 0
0 1 0 1 0 1 0
exit found

1 0 1 1 0 1 0 1 1 1
1 1 1 1 1 1 0 1 0 1
0 0 1 0 0 0 1 1 1 1
0 1 1 1 1 1 1 1 0 1
0 1 0 1 0 1 0 1 0 1
1 1 1 1 1 1 0 1 1 1
0 1 0 1 0 1 0 0 0 1
0 1 1 1 0 1 0 0 0 0
0 1 0 1 0 1 0 1 1 1
0 1 1 1 1 1 0 1 1 1
exit found

1 0 1 1 0 1 1 1 1 0
1 1 1 1 1 1 0 1 0 1
0 0 1 0 0 0 1 1 1 0
0 1 1 1 1 1 1 1 0 1
0 1 0 1 0 1 0 1 0 1
1 1 1 1 1 1 0 1 1 0
0 1 0 1 0 1 0 0 0 0
0 1 1 1 0 1 0 0 1 1
0 1 0 1 0 1 0 1 1 1
0 1 1 1 1 1 0 1 1 1
exit not found

2006-10-09 13:17:07 · 3 answers · asked by Superman049 1 in Computers & Internet Programming & Design

3 answers

The brute force method of maze solution is to always keep to one side. That is, you go down a corridor and take any right turn you come to. If you come to an end, you reverse direction so the right turns are on the other side now. If you come back to your starting point, there's no exit. This strategy has been used by some robot maze runners, but should be pretty simple to adapt to your arrays.

2006-10-09 16:01:29 · answer #1 · answered by injanier 7 · 0 0

i sense assignment... so hints only

i would make a map of the maze in an array, test path to branch, try one path if fail close path and retry from branch until all possible = false or until exit found

eg
1 0 0 0 1
1 1 1 1 0
0 0 1 0 1
0 1 1 1 0
0 0 0 0 1
-----------
1 0 0 0 1
1 1 1 2 0
0 0 1 0 1
0 1 1 1 0
0 0 0 0 1
-----------
1 0 0 0 1
1 1 1 2 0
0 0 1 0 1
0 1 1 2 0
0 0 0 0 1
-----------
1 0 0 0 1
1 1 1 2 0
0 0 1 0 1
0 2 1 2 0
0 0 0 0 1

now all possible paths = 2 therfore no exit

2006-10-09 20:33:34 · answer #2 · answered by icelotuskun 3 · 0 0

What's your question? I'm assuming you want a block diagram for the program. Try this:

start
If left is available, goto [location-1,location]
If straight is available, goto [location, location+1]
If right is available, goto [location+1,location]
end

2006-10-09 20:23:49 · answer #3 · answered by Anonymous · 1 0

fedest.com, questions and answers