牛客网大一大二入门训练(二维数组)

1.图像相似度

x = map(int,input().split())
x = list(x)
m ,n = x[0], x[1]

arrA = [[None]*n for i in range(m)]
arrB = [[None]*n for i in range(m)]

for i in range(m):
    y = list(map(int, input().split()))
    for j in range(n):
        arrA[i][j] = y[j]

for i in range(m):
    y = list(map(int, input().split()))
    for j in range(n):
        arrB[i][j] = y[j]


flag = 0
for i in range(m):
    for j in range(n):
        if arrA[i][j] == arrB[i][j]:
            flag = flag + 1
print("%.2f"%(flag/(m*n)*100))

2.矩阵计算

sum = 0
x = map(int,input().split())
x = list(x)
m ,n = x[0], x[1]

arrA = [[None]*n for i in range(m)]

for i in range(m):
    y = list(map(int, input().split()))
    for j in range(n):
        arrA[i][j] = y[j]

for i in range(m):
    for j in range(n):
        if arrA[i][j] > 0:
            sum = sum + arrA[i][j]

print(sum)
发布了11 篇原创文章 · 获赞 0 · 访问量 90
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览