Question: Board Games Problem Description Ankitha enjoys finding new games. One day, she found a grid with dimensions M * N and decided to make up
Board Games
Problem Description
Ankitha enjoys finding new games. One day, she found a grid with dimensions MN and decided to make up a special game to play on it When Ankitha came up with the idea for the new game, her friend Akhil joined her. She then decided to share and explain the game to him.
Akhil is given a grid with dimensions MN where each cell contains either or Additionally, he is provided with the coordinates of source and destination cells.You can only move to places whose value is Furthermore, he is given the move rule x y which helps in finding the location for the next move. From the given cell, you can move in four directions forward back,right left unless they are out of grid. The rules for finding the next move from a current cell are given below.
For moving forward, add the move rule to the current cell.
For moving right, from current position add the move rule, rotate the path degree clockwise,
For moving left, from current position add the move rule, rotate the path degree anticlockwise direction,
For moving backward, from current position add the move rule, rotate the path degree in clock or anti clockwise.
The rules can be understood better from the following example. Let the current cell be and the move rule as
com.tcscvautomata.eimiddleware.DocxToHtmlConverter@efdef:imagepng
on forward the next cell would be
on right the next cell would be
left and back are out of grid.
Obeying the given move rule, find out minimum how many cells he need to travel in order to reach the destination.
Constraints
M N
Input
First line consist of two space separated integers M and N denoting the number of rows and columns in the grid.
Next M lines consists of N space separated integers representing the grid.
Next line consists of two space separeted integers denoting source cell.
Next line consists of two space separated integers denoting destination cell.
Last line consists of two space separated integer representing move rule.
Output
Print a single integer denoting the minimum moves required to reach the destination.
Time Limit secs
Examples
Example
Input
Output
Explanation
Akhil needs to move from to and the given step for next move is
In order to minimise the number of moves, he follows the path where in total he made moves. No other paths will give moves less than Hence print as the output.
Example
input
Output
Explanation
Akhil needs to move from to and the given step for next move is
In order to minimise the number of moves, he follows the path where in total he made moves. No other paths will give moves less than Hence print as th output.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
