Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- N = int(sys.stdin.readline())
- M = int(sys.stdin.readline())
- Map = [["."] * (M + 2)]
- for i in range(N):
- Map.append(list("." + sys.stdin.readline().rstrip() + '.'))
- Map.append(['.'] * (M + 2))
- for y in range(1, N + 1):
- for x in range(1, M + 1):
- if Map[y][x] == '.' and ( Map[y - 1][x] == '#' or Map[y + 1][x] == '#' or Map[y][x - 1] == '#' or Map[y][x + 1] == '#' or Map[y - 1][x - 1] == '#' or Map[y - 1][x + 1] == '#' or Map[y + 1][x - 1] == '#' or Map[y + 1][x + 1] == '#'):
- Map[y][x] = '*'
- cx = x
- cy = y
- while True:
- sys.stdout.write(str(cy) + ' ' + str(cx) + '\n')
- Map[cy][cx] = '.'
- for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):
- if Map[cy + dy][cx + dx] == '*':
- cx += dx
- cy += dy
- break
- else:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement