关注
'''
10,10
0,0,0,0,0,0,0,0,0,0
0,0,0,1,1,0,1,0,0,0
0,1,0,0,0,0,0,1,0,1
1,0,0,0,0,0,0,0,1,1
0,0,0,1,1,1,0,0,0,1
0,0,0,0,0,0,1,0,1,1
0,1,1,0,0,0,0,0,0,0
0,0,0,1,0,1,0,0,0,0
0,0,1,0,0,1,0,0,0,0
0,1,0,0,0,0,0,0,0,0
output
6,8
'''
import sys
option = [(-1, -1), (-1, 0), (0, -1), (1, -1), (-1, +1), (0, +1), (+1, +1), (+1, 0)]
def get_max_num(list_num, m, n):
list_temp = [[0 for i in range(m)] for j in range(n)]
stacks = []
P = 0
Q = 0
q = 0
for i in range(m):
for j in range(n):
if list_num[i][j] == 1 and list_temp[i][j] == 1:
continue
if list_num[i][j] == 1 and list_temp[i][j] == 0:
P += 1
# print((i,j))
list_temp[i][j] = 1
q += 1
for s in option:
if (i + s[0]) < m and (j + s[1]) < n \
and (i + s[0]) >= 0 and (j + s[1]) >= 0:
if list_num[i + s[0]][j + s[1]] == 1 and list_temp[i + s[0]][j + s[1]] != 1:
stacks.append((i + s[0], j + s[1]))
q += 1
# print(stacks)
while(stacks):
list_n = []
for stack_index in range(len(stacks)):
st = stacks[stack_index]
list_temp[st[0]][st[1]] = 1
for s in option:
if (st[0] + s[0]) < m and (st[1] + s[1]) < n \
and (st[0] + s[0]) >= 0 and (st[1] + s[1]) >= 0:
if list_num[st[0] + s[0]][st[1] + s[1]] == 1 \
and list_temp[st[0] + s[0]][st[1] + s[1]] == 0:
if(st[0] + s[0], st[1] + s[1]) not in stacks:
stacks.append((st[0] + s[0], st[1] + s[1]))
q += 1
list_n.append(stack_index)
# print(stacks, list_n)
list_n.sort(reverse = True)
for ls in list_n:
stacks.pop(ls)
Q = max(Q, q)
q = 0
return P, Q
if __name__ == "__main__":
m, n = sys.stdin.readline().strip().split(',')
list_num = []
for i in range(int(m)):
# 读取每一行
line = sys.stdin.readline().strip()
# 把每一行的数字分隔后转化成int列表
values = list(map(int, line.split(',')))
list_num.append(values)
if m == 0 and n == 0:
print('0,0')
else:
a, b = get_max_num(list_num, int(m), int(n))
print(str(a)+','+str(b))
80...就是过不去
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 我的实习收获 #
8447次浏览 175人参与
# TP-LINK工作体验 #
46706次浏览 825人参与
# 实习吐槽大会 #
10967次浏览 48人参与
# 你的办公桌上都有什么? #
6136次浏览 50人参与
# 晒一晒你的工位 #
77599次浏览 258人参与
# 入职第三天,晒晒你的工位 #
30809次浏览 145人参与
# 实习中的菜狗时刻 #
359415次浏览 3274人参与
# 今年形式下双非本找得到工作吗 #
137869次浏览 1042人参与
# Offer比较,求稳定还是求发展 #
52379次浏览 248人参与
# 来选选带哪个offer回家过年 #
659642次浏览 5271人参与
# 工作压力大怎么缓解 #
78057次浏览 929人参与
# 电网笔面经互助 #
33235次浏览 331人参与
# 薪资一样,你会选择去大厂还是小公司 #
19286次浏览 116人参与
# 24届的你们现状如何了? #
69491次浏览 399人参与
# 我的租房踩坑经历 #
1405次浏览 40人参与
# 你的秋招第一场笔试是哪家 #
129406次浏览 1404人参与
# 高学历就一定能找到好工作吗? #
47257次浏览 583人参与
# 想给25届机械人的秋招建议 #
26454次浏览 219人参与
# 25届非技术实习投递记录 #
116332次浏览 969人参与
# 机械人,你的秋招第一份简历被谁挂了 #
137782次浏览 1972人参与