关注
赶时间瞎写的,凑活着看吧,反正AC了 while 1: try:
m, n = list(map(int, input().split(',')))
mtx = [] for i in range(m):
mtx.append(list(map(int, input().split(',')))) except: break def isValid(x, y): # print(x,y) return x >= 0 and x < m and y >= 0 and y < n
team_count = 0 max_count = 0 seen = set() for i in range(m): for j in range(n): if mtx[i][j] == 0 or (i, j) in seen: continue else:
count = 1 q = [(i, j)]
seen.add((i, j)) while q:
x, y = q.pop() if isValid(x - 1, y) and mtx[x - 1][y] == 1 and (x - 1, y) not in seen:
q.append((x - 1, y))
seen.add((x - 1, y))
count += 1 if isValid(x + 1, y) and mtx[x + 1][y] == 1 and (x + 1, y) not in seen:
q.append((x + 1, y))
seen.add((x + 1, y))
count += 1 if isValid(x, y - 1) and mtx[x][y - 1] == 1 and (x, y - 1) not in seen:
q.append((x, y - 1))
seen.add((x, y - 1))
count += 1 if isValid(x, y + 1) and mtx[x][y + 1] == 1 and (x, y + 1) not in seen:
q.append((x, y + 1))
seen.add((x, y + 1))
count += 1 if isValid(x - 1, y - 1) and mtx[x - 1][y - 1] == 1 and (x - 1, y - 1) not in seen:
q.append((x - 1, y - 1))
seen.add((x - 1, y - 1))
count += 1 if isValid(x - 1, y + 1) and mtx[x - 1][y + 1] == 1 and (x - 1, y + 1) not in seen:
q.append((x - 1, y + 1))
seen.add((x - 1, y + 1))
count += 1 if isValid(x + 1, y - 1) and mtx[x + 1][y - 1] == 1 and (x + 1, y - 1) not in seen:
q.append((x + 1, y - 1))
seen.add((x + 1, y - 1))
count += 1 if isValid(x + 1, y + 1) and mtx[x + 1][y + 1] == 1 and (x + 1, y + 1) not in seen:
q.append((x + 1, y + 1))
seen.add((x + 1, y + 1))
count += 1 if count > max_count:
max_count = count
team_count += 1 print(str(team_count) + ',' + str(max_count))
查看原帖
点赞 1
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 牛客新年AI问运 #
8911次浏览 123人参与
# 你喜欢工作还是上学 #
89622次浏览 885人参与
# 牛客AI体验站 #
16816次浏览 292人参与
# 被AI治愈的瞬间 #
90840次浏览 687人参与
# 你找工作的时候用AI吗? #
173532次浏览 890人参与
# 有必要和同事成为好朋友吗? #
1461次浏览 31人参与
# 如何提高实习转正率? #
87230次浏览 510人参与
# 听劝,这个公司值得去吗 #
665917次浏览 1996人参与
# 你觉得什么岗位会被AI替代 #
41419次浏览 278人参与
# 为了秋招你都做了哪些准备? #
32683次浏览 534人参与
# 机械人的薪资开到多少,才适合去? #
165267次浏览 573人参与
# 你最满意的offer薪资是哪家公司? #
71610次浏览 355人参与
# 这个工作能去吗 #
115420次浏览 663人参与
# 多益网络工作体验 #
63388次浏览 306人参与
# 工作中的卑微时刻 #
33622次浏览 199人参与
# 秋招吐槽大会 #
305005次浏览 1524人参与
# 央国企投递记录 #
177158次浏览 1655人参与
# 国央企求职进展汇总 #
442937次浏览 3509人参与
# 数字马力求职进展汇总 #
331901次浏览 2381人参与
# 你已经投递多少份简历了 #
1353576次浏览 10821人参与
曼迪匹艾公司福利 149人发布