Advertisement
ilnurav

Untitled

Apr 4th, 2020
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import sys
  2. N = int(sys.stdin.readline())
  3. M = int(sys.stdin.readline())
  4. Map = [["."] * (M + 2)]
  5. for i in range(N):
  6. Map.append(list("." + sys.stdin.readline().rstrip() + '.'))
  7. Map.append(['.'] * (M + 2))
  8. for y in range(1, N + 1):
  9. for x in range(1, M + 1):
  10. if Map[y][x] == '.' and (
  11. Map[y - 1][x] == '#' or Map[y + 1][x] == '#' or
  12. Map[y][x - 1] == '#' or Map[y][x + 1] == '#' or
  13. Map[y - 1][x - 1] == '#' or Map[y - 1][x + 1] == '#' or
  14. Map[y + 1][x - 1] == '#' or Map[y + 1][x + 1] == '#'):
  15. Map[y][x] = '*'
  16. cx = x
  17. cy = y
  18. while True:
  19. sys.stdout.write(str(cy) + ' ' + str(cx) + '\n')
  20. Map[cy][cx] = '.'
  21. for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):
  22. if Map[cy + dy][cx + dx] == '*':
  23. cx += dx
  24. cy += dy
  25. break
  26. else:
  27. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement