Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun input(n: Int, m: Int, N: Array<BooleanArray>) {
- for (i in 1 until n - 1)
- for (j in 1 until m - 1)
- N[i][j] = scan.nextInt() == 0
- }
- fun findWay(x: Int, y: Int, field: Array<BooleanArray>): Boolean {
- if (x == field.size-2 && y == field[field.size-2].size-2) return true
- else {
- if (field[x+1][y]) {
- field[x+1][y] = false
- if (findWay(x+1, y, field)) return true
- }
- if (field[x-1][y]) {
- field[x-1][y] = false
- if (findWay(x-1, y, field)) return true
- }
- if (field[x][y+1]) {
- field[x][y+1] = false
- if (findWay(x, y+1, field)) return true
- }
- if (field[x][y-1]) {
- field[x][y-1] = false
- if (findWay(x, y-1, field)) return true
- }
- }
- return false
- }
- fun main(args: Array<String>) {
- val n = scan.nextInt()+2
- val m = scan.nextInt()+2
- val checker = Array(n, {BooleanArray(m)})
- input(n, m, checker)
- print(findWay(1,1,checker))
- }
- /*4 7
- 0 1 0 0 0 1 0
- 0 1 0 1 0 0 0
- 0 0 0 1 1 1 0
- 1 1 1 0 0 1 0*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement