Advertisement
zhukov000

Untitled

Nov 25th, 2021
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. A = [
  2.   [0,0,0,0,0,0,0,0],
  3.   [0,1,1,1,1,0,0,0],
  4.   [0,0,0,0,0,0,0,0],
  5.   [0,0,0,0,0,0,0,0],
  6.   [0,0,0,0,0,0,0,0],
  7.   [0,0,0,0,0,0,0,0],
  8.   [0,0,0,1,1,1,1,0],
  9.   [0,0,0,0,0,0,0,0]
  10. ]
  11.  
  12. def pos(x, y):
  13.   return min(x, y) >= 0 and max(x, y) < 8
  14.  
  15. def check(si, sj):
  16.   B = [[A[i][j] for j in range(8)] for i in range(8)]
  17.   B[si][sj] = 1
  18.   while True:
  19.     if pos(si + 1, sj) and B[si + 1][sj] == 0:
  20.       si += 1
  21.     elif pos(si, sj + 1) and B[si][sj + 1] == 0:
  22.       sj += 1
  23.     elif pos(si - 1, sj) and B[si - 1][sj] == 0:
  24.       si -= 1
  25.     elif pos(si, sj - 1) and B[si][sj - 1] == 0:
  26.       sj -= 1
  27.     else:
  28.       break
  29.     B[si][sj] = 1
  30.   return sum([sum(r) for r in B]) == 64
  31.  
  32. k = 0
  33. for i in range(8):
  34.   for j in range(8):
  35.     if A[i][j] == 0 and check(i, j):
  36.       print(i, j)
  37.       k += 1
  38. print('Ответ', k)
  39.      
  40.      
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement