Java Program
Problem Statement
A game is made around the basic concept of a man pushing a box in a maze, from its source to its destination. The maze consists of cells that are empty or have obstacles. The box is heavy and a man can push it from one cell to an adjacent cell only if he is exactly behind the box. If there is no space for the man behind the box, then the box cannot be pushed in that direction. On pushing, the box is moved to an adjacent cell based on the direction in which the man has pushed. The box can only be pushed to its four-adjacent cells, and hence diagonal move of the box is not possible
You are given a rectangular matrix representing the maze. There is one man, one box and one destination cell, in the maze. The task is to push the box to its destination. There are obstacles in the maze that hinder the movement of the box. There is a unique path for the box to move from its initial position to its destination.
Note that a man, when he is not pushing the box, can jump from a cell to any other empty cell. Hence the presence of obstacles or the box in between does not hinder the man's movement from one empty cell to another, as is necessitated in the second sample input. The destination can be considered an empty cell, as far as the man's movement is concerned.
Given a rectangular matrix representing the maze as input, you have to output the length of the path taken by the box in moving to its destination. The length of the path will always be greater than or equal to one.
In the sample matrix, the only path for the box to move from its initial position to the destination cell is as shown by the arrows. Hence, the length of the path in this particular case is five. Satisfy yourself that there exist no other paths, which can be followed for moving the box to its destination cell.
Input Specification
The first line contains two integers R and C denoting the number of rows and columns of the matrix respectively.
The matrix of characters then follows where
B indicates the initial position of the box.
M indicates the position of the man.
D indicates the destination of the box
indicates an obstacle
@ indicates a free cell
The matrix is given in the form of R lines each containing C consecutive characters.
Output Specification
The output should be the length of the path terminated by a newline.
Sample Test Cases
Test Case 1
Input:
5 5
@@@D@
@##@@
@##@@
MB@@@
@@@@@
Output:
5
Test Case 2
Input:
6 5
@@@@@
@@@@@
D@#@@
@@
@B@@@
@@M@
Output:
9
View Answers
Related Tutorials/Questions & Answers:
java program for java program for
java program for printing documents,images and cards
a Java program a
Java program
Write a
Java program to print even numbers from 2 to 1024?
Write a
Java program to print ? My Name is Mirza? 100 times?
Write a
Java program to print Fibonacci Series?
Write a
Java program to reverse a number
Advertisements
Java ProgramJava Program A
Java Program that print the data on the printer but buttons not to be printed
java programjava program write a
program to print
1234
567
89
10
java programjava program Write a
program to demonstrate the concept of various possible exceptions arising in a
Java Program and the ways to handle them.
... in
Java java programjava program write
java program for constructor,overriding,overriding,exception handling
java programjava program how to write an addition
program in
java without using arithematic operator
java programjava program write a
java program to display array list and calculate the average of given array
java programjava program write a
java program to display array list and calculate the average of given array
Java ProgramJava Program
java program to insert row in excel sheet after identifying an object
java programjava program
java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
java programjava program Write a
java program to do matrix addition operation
On two given matrices
java programjava program Write a
java program to find the number of
Positive numbers in m* n matrix
java programjava program Write a
program to create an applet and display
The message "welcome to
java java programjava program hi friends how to make a
java program for getting non prime odd numbers in a given series
java programjava program Write a
program to find the difference between sum of the squares and the square of the sums of n numbers
java programjava program write a
program to create text area and display the various mouse handling events
java programjava program Develop the
program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The
program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java programjava program . Develop the
program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The
program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java programjava program . Write a
program which performs to raise a number to a power and returns the value. Provide a behavior to the
program so as to accept any type of numeric values and returns the results
Java programJava program Write a
program which performs to raise a number to a power and returns the value. Provide a behavior to the
program so as to accept any type of numeric values and returns the results
program in javaprogram in java write a reverse
program in
java using string buffer.the input and out put as follows.
input- hi good mornig
out put-ih doog ginrom
java programjava program write a
java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java programjava program write a
java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java program java program A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
java program to display above triangle
java programjava program write a
program to create server and client such that server receives data from client using BuuferedReader and sends reply to client using PrintStream
java programjava program write a
program to read 10 numbers from user and store it in a array. display the maximum n minimum number in the array
java programjava program write a
java program to read a file which hold email address validate email address tohave formate @.* and replace all .com email address
java programjava program write a
java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java programjava program write a
java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java programjava program write a
java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
Java ProgramJava Program I want to Write a
program in
JAVA to display to create a class called MATRIX using a two-dimensional array of integers. Perform the addition and subtraction of two matrices.
Help me
java programjava program i want a applet
program that accepts two input strings using tag and concatenate the strings and display it in status window.
please give mi he code for this in core
java java programjava program i want a applet
program that accepts two input strings using tag and concatenate the strings and display it in status window.
please give mi he code for this in core
java java programjava program i want a applet
program that accepts two input strings using tag and concatenate the strings and display it in status window.
please give mi he code for this in core
java java programjava program Write a
program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The
program lets the user enter the interest rate, number of years, loan amount, and displays
java programjava program . Develop a
program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time
java programjava program write a
program that accepts only 3 integer values as command line arguments.print the values enter by the user. handle ArrayIndexOutofbounds exception and number format exception by providing appropriate message
java programjava program write a
program showing two threads working simultanously upon two objects(in theater one object "cut the ticket" andsecond object "show is the seat
A java ProgramA
java Program Write a
java program, which provides a text area with horizontal and vertical scrollbar.Type some lines in the text area and use scrollbars to move the text within the text area.Read a word in a text field
java programjava program write a
java program to display the following output.
[email protected]
1] Symbol @ cannot come for first letter
2] @ symbol only come at one time.
3] .com should be come for after the mail id
a java programa
java program Write a
java program that accepts positive numbers... through the link may, this will be helpful for you
http://www.roseindia.net/
java/thread/
java-multithreading-example.shtml
Thanks
java programjava program Develop the
program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g â?¢ t in t time units
java programjava program Develop the
program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g ? t in t time units
java programjava program Hi,
can any one solve this
program for me.
Q.In a knock-out tennis tournament(Singles).
(A)N players participate.
(B)construct a data structure to represent the results optimized to find the winners.
(C
Java ProgramJava Program Write a
Java program so that when the
program is executed, a window will appear with white background. The window should be of size 400x400 pixels. Then when the user clicks at the window, a circle of size 20
Java ProgramJava Program Write a
Java program so that when the
program is executed, a window will appear with white background. The window should be of size 400x400 pixels. Then when the user clicks at the window, a circle of size 20
java programjava program write a
java program which shows how to declare and use STATIC member variable inside a
java class.
The static variable are the class variables that can be used without any reference of class.
class
java programjava program write a
java program to read a file content into a string object using available and read methods of
java bufferedinputstream.
Please visit the following link:
http://www.roseindia.net/
java/example/
java java programjava program write a
java script
program that would input the ff... and below no discount
write a
java script
program that would...%
84 and below no discount
write a
java script
program