Skip to content

Instantly share code, notes, and snippets.

@nattybear
Last active July 22, 2022 12:46
Show Gist options
  • Save nattybear/dca95f989346541817f8f3025028faf9 to your computer and use it in GitHub Desktop.
Save nattybear/dca95f989346541817f8f3025028faf9 to your computer and use it in GitHub Desktop.
1 1
0
2 2
0 1
1 0
3 2
1 1 1
1 1 1
5 4
1 0 1 0 0
1 0 0 0 0
1 0 1 0 1
1 0 0 1 0
5 4
1 1 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 1 1
5 5
1 0 1 0 1
0 0 0 0 0
1 0 1 0 1
0 0 0 0 0
1 0 1 0 1
0 0
import java.util.*;
public class Main {
static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
while (true) {
int w = sc.nextInt();
int h = sc.nextInt();
if (w != 0 && h != 0)
solution(w, h);
else
break;
}
}
static void solution(int w, int h) {
int[][] map = new int[h][w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
map[i][j] = sc.nextInt();
}
static void dfs(int[][] map, int w, int h) {
List<Integer> visit = new ArrayList<>();
Stack<Square> stack = new Stack<>();
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
stack.push(new Square(i, j));
}
}
class Square {
int row;
int column;
Square(int r, int c) {
row = r;
column = c;
}
List<Square> getWalkables(int[][] map, int w, int h) {
List<Square> walkables = new ArrayList<>();
for (int i = row-1; i <= row+1; i++)
for (int j = column-1; j <= column+1; j++)
if (0 <= i && i < h && 0 <= j && j < w)
if (map[i][j] == 1)
walkables.add(new Square(i, j));
return walkables;
}
}
run: compile
@java Main < input.txt
compile:
@javac Main.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment