就是求内部矩形的大小,主要问题是根据题意判断起点和终点
参考代码:
#肿瘤与边缘之间必须被0分隔开(未完全分隔就不算答案) n = int(input()) arr = [list(map(int, (input().split()))) for _ in range(n)] res = 0 flag = False start = [0, 0] end = [0, 0] for i in range(1, n - 1): for j in range(1, n - 1): if arr[i][j] > 0: if arr[i + 1][j] == 0 and arr[i][j + 1] == 0: end[0], end[1] = i, j if not flag and arr[i - 1][j] == 0 and arr[i][j - 1] == 0: flag = True start[0], start[1] = i, j res = (end[0] - start[0] + 1) * (end[1] - start[1] + 1) if end[0] == 0: print(0) else: print(res)
0.0分
0 人评分