res = 0
direction = [[1,0],[0,1],[-1,0],[0,-1]]
def dfs(grap,x,y):
for i ,j in direction:
curx = i+x
cury = j+y
if grap[curx][cury] == 0 :
global res
res += 1
n, m = map(int,input().split())
grap = [[0]*(m+2)]
for i in range(n):
grap.append([0]+list(map(int,input().split()+[0])))
grap.append([0]*(m+2))
for i in range(1,n+1):
for j in range(1,m+1):
if grap[i][j] == 1 :
dfs(grap,i,j)
print(res)
岛屿的周长
最新推荐文章于 2025-06-14 09:35:25 发布