Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5-3 The Labyrinth of Romeo and Juliet Problem Description: The Labyrinth of Romeo and Juliet. Romeo and Juliet are in an mn maze, as shown.
5-3 The Labyrinth of Romeo and Juliet Problem Description: The Labyrinth of Romeo and Juliet. Romeo and Juliet are in an mn maze, as shown. Each square represents a room in the maze. Some of these mn rooms are closed and no one is allowed to enter. You can enter an unclosed room in 8 directions from anywhere in the maze. Romeo is in the ( p,q) square of the maze, and he has to find a way to the (r,s) square where Juliet is. Before reaching Juliet, he must walk through all the unsealed rooms once, and minimize the number of turns to Juliet. Each change of heading counts as a turn. Please design an algorithm to help Romeo find such a path: For a given Romeo and Juliet maze, program to calculate all the least-turn paths for Romeo to Juliet. data input: The first line has 3 positive integers n,m,k, which represent the number of rows, columns and closed rooms of the maze, respectively. In the next k lines, each line contains 2 positive integers, indicating the row number and column number of the closed room. The last 2 lines also contain 2 positive integers, which represent the square (p,q) where Romeo is located and the square (r,s) where Juliet is located. Result output: Take the calculated minimum number of turns from Romeo to Juliet and how many different minimum turn roads are output. The first line of the file is the minimum number of turns. Line 2 of the file is the number of different minimum turns. The next n lines each have m numbers, which represent a minimum turning road of the maze. A[i][j]=k means that the k-th step reaches square (i.j); A[i][j]=1 means that square (i,j) is closed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started