DSTJZ


私信TA

用户名:dotcpp0721777

访问量:5417

签 名:

天下难事,必作于易;天下大事,必作于细。

等  级
排  名 48
经  验 11305
参赛次数 13
文章发表 322
年  龄 18
在职情况 学生
学  校 狗熊岭23届毕业生
专  业

  自我简介:

TA的其他文章

java--study||O.o
浏览:29
java--study||O.o
浏览:24
java--study||O.o
浏览:41


参考代码:

dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)


def judge(x, y):
    if x == 0 or x == n - 1 or y == 0 or y == n - 1:
        return True
    for d in range(4):
        tx, ty = x + dx[d], y + dy[d]
        if 0 <= tx < n and 0 <= ty < n and arr[tx][ty] > 50:
            return True
    return False


n = int(input())
arr = [list(map(int, input().split())) for _ in range(n)]
square = 0
circumference = 0
for i in range(n):
    for j in range(n):
        if arr[i][j] <= 50:
            square += 1
            if judge(i, j):
                circumference += 1
print(square, circumference)


 

0.0分

0 人评分

  评论区