Advertisement
jootiee

Untitled

Dec 7th, 2021
843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. from pprint import pprint as print
  2.  
  3. '''
  4. 1 1 1 0 0 1 0
  5. 1 0 1 0 0 1 0
  6. 1 0 1 1 1 1 0
  7. 0 1 0 0 1 0 0
  8. 0 1 0 0 1 1 0
  9. 0 1 1 1 0 0 0
  10. счет с единицы, первая коорд-а - y
  11. '''
  12.  
  13. field = list()
  14. height, width = map(int, input().split())
  15. for _ in range(height):
  16.     field.append(list(input()))
  17. res = ""
  18.  
  19. for _ in range(int(input())):
  20.     temp = list(map(int, input().split()))
  21.     start, end = temp[:2], temp[2:]
  22.  
  23.     if start == end:
  24.         res += "1"
  25.         continue
  26.     if field[start[1] - 1][start[0] - 1] == "0":
  27.         res += "0"
  28.         continue
  29.  
  30.     c = start[1]
  31.     curves = 0
  32.     r = start[0]
  33.     down = False
  34.     while True:
  35.         if curves == 3:
  36.             res += "0"
  37.             break
  38.         if [c, r] == end:
  39.             res += "1"
  40.             break
  41.         try:
  42.             curcell = field[c - 1][r - 1]
  43.         except:
  44.             res += "0"
  45.             break
  46.         if curcell == "1":
  47.             r += 1
  48.         else:
  49.             r -= 1
  50.             c += 1
  51.             curves += 1
  52.  
  53. print(res)
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement