• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Apr 24th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. moveX = (+1, +1, +1, +0, +0, -1, -1, -1)
2. moveY = (-1, +0, +1, -1, +1, -1, +0, +1)
3.
4. while True:
5.   n, m = map(int, input().split())
6.   if n == 0 and m == 0:
7.     break
8.
9.   def floodfill(matrix: list, i: int, j: int) -> None:
10.     if i < 0 or i >= n or j < 0 or j >= m: return
11.     if matrix[i][j] == '*': return
12.     matrix[i][j] = '*'
13.     for move in range(8):
14.       floodfill(matrix, i+moveX[move], j+moveY[move])
15.
16.   count = 0
17.   matrix = [['' for i in range(m)] for i in range(n)]
18.   for i in range(n):
19.     matrix[i] = list(input())
20.
21.   for i in range(n):
22.     for j in range(m):
23.       if matrix[i][j] != '*':
24.         floodfill(matrix, i, j)
25.         count += 1
26.   print(count)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top