CSP 202006-2 稀疏矩阵 python 模拟
题目描述
思路
暴力模拟即可得到答案,我们可以用Python的字典,找到相同的键就将值进行相乘即可
代码
n,a,b = map(int,input().split())
d1,d2 = {
},{
}
for i in range(a):
index,value = map(int,input().split())
d1[index] = value
for i in range(b):
index,value = map(int,input().split())
d2[index] = value
ans = 0
for k,v in d1.items():
if k in d2:
ans += v * d2[k]
print(ans)