OPPO CV笔试一题

binaryImage = [[0, 1, 0], [1, 0, 1], [1, 0, 1], [1, 0, 1], [0, 0, 0]]
# binaryImage = [[0, 1, 0, 0], [1, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 1], [0, 1, 1, 1]]
row = len(binaryImage)
col = len(binaryImage[0])
zuobiao = set()  # 1像素坐标
zeros = set()  # 环内0
ring = 1
for i in range(row):
    for j in range(col):
        if binaryImage[i][j] == 0:
            need = [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]
            ans = 0
            for k in need:
                if 0 <= k[0] < row and 0 <= k[1] < col and binaryImage[k[0]][k[1]] == 1:
                    ans += 1
                if 0 <= k[0] < row and 0 <= k[1] < col and (k[0], k[1]) in zeros:
                    ans += 1
            if ans >= 3:
                zeros.add((i, j))
if len(zeros) == 0:
    print(0)
else:
    for zero in zeros:
        i = zero[0]
        j = zero[1]
        need = [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]
        for k in need:
            if 0 <= k[0] < row and 0 <= k[1] < col and binaryImage[k[0]][k[1]] == 1:
                zuobiao.add((k[0], k[1]))
            if 0 <= k[0] < row and 0 <= k[1] < col and binaryImage[k[0]][k[1]] == 0 and (k[0], k[1]) not in zeros:
                ring = 0
                break
    if ring == 0:
        print(0)
    else:
        print(len(zuobiao))

#OPPO##笔经#
全部评论

相关推荐

我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
测试糕手手:社会第一课,随便吹牛逼,直接说四个月,别老实。老实人只会被欺负
点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务