Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. import sys
  2. import math
  3. # Don't let the machines win. You are humanity's last hope...
  4.  
  5. width = int(input()) # the number of cells on the X axis
  6. height = int(input()) # the number of cells on the Y axis
  7. line = []
  8. for i in range(height):
  9. line.append(list(input()))
  10. #print(input())
  11. # Write an action using print
  12. # To debug: print("Debug messages...", file=sys.stderr)
  13. #line = [[["0"],["0"],["0"]]]
  14. answer = ""
  15.  
  16. def checkSafeNode(x,y,answer):
  17. if(line[y][x] == "0"):
  18. answer += (str(x) + " " + str(y) + " ")#(str(i) + " " + str(j) + " ")
  19.  
  20. if(line[y][x+1] == "0"):
  21. answer += (str(x+1) + " " + str(y) + " ")#(str(i) + " " + str(j + 1) + " ")
  22. #line[i][j+1] = "."
  23. else:
  24. answer += ("-1 -1 ")
  25.  
  26. if(line[y+1][x] == "0"):
  27. answer += (str(x) + " " + str(y+1) + ", ")#(str(i+1) + " " + str(j) + " ")
  28. #line[i+1][j] = "."
  29. else:
  30. answer += ("-1 -1, ")
  31. return answer
  32.  
  33. def checkWidthNode(x,y,answer):
  34. if(line[y][x] == "0"):
  35. answer += (str(x) + " " + str(y) + " ")#(str(i) + " " + str(j) + " ")
  36. answer += ("-1 -1 ")
  37.  
  38. if(line[y+1][x] == "0"):
  39. answer += (str(x) + " " + str(y+1) + ", ")#(str(i+1) + " " + str(j) + " ")
  40. #line[i+1][j] = "."
  41. else:
  42. answer += ("-1 -1, ")
  43. return answer
  44.  
  45. def checkHeightNode(x,y,answer):
  46. if(line[y][x] == "0"):
  47. answer += (str(x) + " " + str(y) + " ")#(str(i) + " " + str(j) + " ")
  48.  
  49. if(line[y][x+1] == "0"):
  50. answer += (str(x+1) + " " + str(y) + " ")#(str(i) + " " + str(j + 1) + " ")
  51. #line[i][j+1] = "."
  52. else:
  53. answer += ("-1 -1 ")
  54.  
  55. answer += ("-1 -1, ")
  56. return answer
  57.  
  58. def checkFinalNode(x,y,answer):
  59. if(line[y][x] == "0"):
  60. answer += (str(x) + " " + str(y) + " ")#(str(i) + " " + str(j) + " ")
  61. answer += ("-1 -1 ")
  62. answer += ("-1 -1, ")
  63. return answer
  64.  
  65.  
  66. for y in range(height):
  67. for x in range(width):
  68. if(y < (height-1) and x < (width-1)):
  69. answer = checkSafeNode(x,y,answer)
  70. elif(x == (width-1) and y < (height-1)):
  71. answer = checkWidthNode(x,y,answer)
  72. elif(y == (height-1) and x < (width-1)):
  73. answer = checkHeightNode(x,y,answer)
  74. elif(y == (height-1) and x == (width-1)):
  75. answer = checkFinalNode(x,y,answer)
  76.  
  77.  
  78.  
  79. answer = answer.split(",")
  80.  
  81. for i in answer:
  82. print(i)
  83.  
  84. # Three coordinates: a node, its right neighbor, its bottom neighbor
  85. #print("0 0 1 0 0 1")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement