Skip to content

Instantly share code, notes, and snippets.

@nareshdb
Created December 2, 2016 03:14
Show Gist options
  • Save nareshdb/6551931b0e65c79879f7dfbcc4f2c43a to your computer and use it in GitHub Desktop.
Save nareshdb/6551931b0e65c79879f7dfbcc4f2c43a to your computer and use it in GitHub Desktop.
Foo4
import java.util.*;
class Foo4{
public static void main(){
int mat[18][20] =
{
{ 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,1, 0, 1, 1, 1, 1, 0, 1, 1, 1 },
{ 1, 0, 1, 0, 1, 1, 1, 0, 1, 1 ,1, 0, 1, 0, 1, 1, 1, 0, 1, 1 },
{ 1, 1, 1, 0, 1, 1, 0, 1, 0, 1 ,1, 1, 1, 0, 1, 1, 0, 1, 0, 1 },
{ 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 ,0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 ,1, 1, 1, 0, 1, 1, 1, 0, 1, 0 },
{ 1, 0, 1, 1, 1, 1, 0, 1, 0, 0 ,1, 0, 1, 1, 1, 1, 0, 1, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 ,1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 1, 1, 1, 1, 0, 1, 1, 1 ,1, 0, 1, 1, 1, 1, 0, 1, 1, 1 },
{ 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1 },
{ 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,1, 0, 1, 1, 1, 1, 0, 1, 1, 1 },
{ 1, 0, 1, 0, 1, 1, 1, 0, 1, 1 ,1, 0, 1, 0, 1, 1, 1, 0, 1, 1 },
{ 1, 1, 1, 0, 1, 1, 0, 1, 0, 1 ,1, 1, 1, 0, 1, 1, 0, 1, 0, 1 },
{ 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 ,0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 ,1, 1, 1, 0, 1, 1, 1, 0, 1, 0 },
{ 1, 0, 1, 1, 1, 1, 0, 1, 0, 0 ,1, 0, 1, 1, 1, 1, 0, 1, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 ,1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, , 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1 }
};
int ans = answer(mat);
System.out.println(ans);
}
public​ ​static​ ​int​ ​answer(int[][]​ ​maze)​ ​{​ ​
​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​class point{
public int x;
public int y;
point(int x, int y){
this.x = x;
this.y = y;
}
}
class queueNode{
public Point pt;
int dist;
queueNode(Point pt, int dist){
this.pt = pt;
this.dist = dist;
}
}
bool isValid(int row, int col){
return (row >= 0) && (row < maze.length) && (col >= 0) && (col < maze[0].length));
}
int rowNum[] = { -1, 0, 0, 1};
int colNum[] = { 0, -1, 1, 0};
Point src = new Point(0,0);
Point dest = new Point(maze.length, maze[0].length);
bool visited[maze.length][maze[0].length];
Arrays.fill(visited, false);
visited[0][0] = true;
queue<queueNode> q = new queue<queueNode>;
queueNode s = new queueNode(src.x, src.y)
​ ​​ ​​ ​​ ​
q.push(s);
while(!q.empty()){
queueNode curr = new q.fo
}
}​ ​
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment