ALgorocks
BAN USER- 0of 0 votes
AnswersMaga gives a hard problem to Alex. And Alex couldn't solve yet. Could you help him?
- ALgorocks in India
The grid is n by m. Each cell contains a unique number on it. Maga is at the left-top and wants to go to right-bottom. But there is a condition. Maga can go through only two way - right and down. And the path of your move is called the nodes you have passed through over them. The path is called the most beautiful if the following condition is satisfied: The sorted of the path has to be lexicographic smallest as possible as. Output the most beautiful path for given grid.
Input:
In the first line you are given two numbers: the dimensions of grid - n and m. The next n lines contains m numbers. Each number is unique.
Output:
Output the most beautiful path.
Contraints:
1 <= n,m <= 1000
1 <= A[i][j] <= n*m, All of the numbers in the grid are unique.
Sample Input
2 2
4 2
3 1
Sample Output
1 2 4
Explanation
There are 2 ways to reach at (2,2) cell. The pathes are 4, 3, 1 or 4, 2, 1 respectively. So The most beautiful of them is 4, 2, 1 because if looking the sorted of them it looks like these : 1, 3, 4 and 1, 2, 4 respectively. So 1, 2, 4 is lexicographic smaller than the other. So the ans is 1 2 4.| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersLittle Chandan is a friend everyone feels lucky to have. He is a happy-go-lucky-fellow and makes sure that everyone around him is happy. But recently, he came to know that his friend little Arjit is in serious trouble, and needs help. Like the great friend little Chandan is, he took the challenge upon himself without any serious thought, to make sure that little Arjit feels fine.
- ALgorocks in India
Now, little Arjit explains the story of his problems (His life, in general!) to let little Chandan figure out his troubles. After all, everyone needs help. All little Arjit needs is to get an internship somewhere, and complete his dual degree course, somehow, anyhow.
Little Chandan being the great genius man with psychic power decides to enter the brain of his friend to help him out.
Here are the contents of little Arjit's brain:
- His goals. (Internship, dual degree, remember?) - what Chandan needs to free. - Predictable empty spaces in his brain - plain empty spaces. - Ex-girlfriends and their memories - which CANNOT be penetrated, while traversing. - Windows which lead to the goal - which need to be open for little Chandan to pass.
Little Chandan knows the location of the two goals in his brain, the problem is while traveling through the path of his brain he'll have to break down the windows - once he has opened a window to cross that path, it remains open forever. So, he wants to minimize the number of windows he opens inside his friend's mind.
Help him plan his path accordingly, so he ends up breaking the minimum number of windows!
Input Format:
- First line contains a number t, denoting the number of test cases.
- Every test case will have the following:
- One line with two integers hm, wm - determining the width of the brain and the height of the brain.
The following characters define the state:
- X is the space which cannot be penetrated filled by the memories of ex-girlfriends. - W is the windows which little Chandan need to cross to reach the goal. - . is an empty space in the brain. - G are the two goals to be rescued.
Output Format:
1. Minimum number of windows Chandan needs to open to get to both the goals in Arjit's mind.
Constraints:
1 <= t <= 100
2 <= hm, wm <= 100
There are EXACTLY two goals in his mind.
For each goal, a path from the outside to that goal is surely going to exist.
Chandan can move around freely outside the mind.
Sample Input
1
5 9
XXXXWXXXX
X..W.W..X
XXXX.XXXX
XGW.W.WGX
XXXXXXXXX
Sample Output
4| Report Duplicate | Flag | PURGE
Algorithm
This is the complete question which I got. I am also confuse little bit but as I can understand.
- ALgorocks July 28, 2015As in question chandan can moves freely outside brain, so it can move arround give matrix. He can entre from (0,5) where he can found "W" and then move three steps down W... ,after that in fourth row, he can move left right and can found 3 more "W" and 2 "G" and come out from same path