Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import math
- # Don't let the machines win. You are humanity's last hope...
- width = int(input()) # the number of cells on the X axis
- height = int(input()) # the number of cells on the Y axis
- line = []
- for i in range(height):
- line.append(list(input()))
- #print(input())
- # Write an action using print
- # To debug: print("Debug messages...", file=sys.stderr)
- #line = [[["0"],["0"],["0"]]]
- answer = ""
- def checkSafeNode(x,y,answer):
- if(line[y][x] == "0"):
- answer += (str(x) + " " + str(y) + " ")#(str(i) + " " + str(j) + " ")
- if(line[y][x+1] == "0"):
- answer += (str(x+1) + " " + str(y) + " ")#(str(i) + " " + str(j + 1) + " ")
- #line[i][j+1] = "."
- else:
- answer += ("-1 -1 ")
- if(line[y+1][x] == "0"):
- answer += (str(x) + " " + str(y+1) + ", ")#(str(i+1) + " " + str(j) + " ")
- #line[i+1][j] = "."
- else:
- answer += ("-1 -1, ")
- return answer
- def checkWidthNode(x,y,answer):
- if(line[y][x] == "0"):
- answer += (str(x) + " " + str(y) + " ")#(str(i) + " " + str(j) + " ")
- answer += ("-1 -1 ")
- if(line[y+1][x] == "0"):
- answer += (str(x) + " " + str(y+1) + ", ")#(str(i+1) + " " + str(j) + " ")
- #line[i+1][j] = "."
- else:
- answer += ("-1 -1, ")
- return answer
- def checkHeightNode(x,y,answer):
- if(line[y][x] == "0"):
- answer += (str(x) + " " + str(y) + " ")#(str(i) + " " + str(j) + " ")
- if(line[y][x+1] == "0"):
- answer += (str(x+1) + " " + str(y) + " ")#(str(i) + " " + str(j + 1) + " ")
- #line[i][j+1] = "."
- else:
- answer += ("-1 -1 ")
- answer += ("-1 -1, ")
- return answer
- def checkFinalNode(x,y,answer):
- if(line[y][x] == "0"):
- answer += (str(x) + " " + str(y) + " ")#(str(i) + " " + str(j) + " ")
- answer += ("-1 -1 ")
- answer += ("-1 -1, ")
- return answer
- for y in range(height):
- for x in range(width):
- if(y < (height-1) and x < (width-1)):
- answer = checkSafeNode(x,y,answer)
- elif(x == (width-1) and y < (height-1)):
- answer = checkWidthNode(x,y,answer)
- elif(y == (height-1) and x < (width-1)):
- answer = checkHeightNode(x,y,answer)
- elif(y == (height-1) and x == (width-1)):
- answer = checkFinalNode(x,y,answer)
- answer = answer.split(",")
- for i in answer:
- print(i)
- # Three coordinates: a node, its right neighbor, its bottom neighbor
- #print("0 0 1 0 0 1")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement