Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Jack is very fond of his girlfriend, Jilly. He is ready to go M miles to meet Jilly, and he

knows Jilly loves surprises. So, he decides to pick up some goodies for her on his way

and sets out on this journey with R rupees in his wallet.

On his way, Jack finds shops of four types. The shops along with the minimum cost of

each item is given below:

Dresses - Rs. 2000

Shoes - Rs.1000

Chocolates - Rs.500

Flowers - Rs.500

Jack wants to give Jilly as many gifts as possible, so he is reluctant to spend more

than the minimum amount at each shop and he would prefer to buy two different

items of the same cost rather than spend the lot on buying more of the same item.

Given a map from Jack's location to Jilly's, you are asked to help Jack decide which

way to go, such that he can pick up maximum number of goodies for Jilly and get to

her as fast as possible.

Input :

The first line of input denotes the number of testcases T. The first line of each

testcase has two space-separated values R and M. The second line defines the

matrix NxM which represents the map. The following N lines define the 2D array

which represents the map from Jack's location to Jilly's. Dresses are represented

by D, Shoes by S, Choloates by C and Flowers by F; Jack by J and Jilly by G.

Assume that moving from one block on the map to its adjacent block covers a

distance of 1 mile.

Output :

The first line of output should represent the number of miles that Jack has

travelled. The second line follows to display all the different blocks that he visited

as shown in the sample output. Print -1 if it is not possible for Jack to meet Jilly.

Confidential: rapidBizApps Screening Problem-Set.

Do not share/distribute without prior written approval from rapidBizApps

Sample Input :

2

3000 10

5 7

J # # # # # #

# # D1 # C1 # #

# # # # # # G

# # C2 # # F1 #

# # # # # # #

Sample Output :

10

J # # # # # #

| - D1 # C1 # #

# # | # # # G

# # C2 - - F1 |

# # # # # # #
Posted
Comments
Afzaal Ahmad Zeeshan 26-Dec-14 8:38am    
Please be specific while asking questions, this is not the way to ask and get help from CodeProject.
[no name] 26-Dec-14 8:40am    
Sample Solution: /...;)0

1 solution

We still do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900