CSP 202006-2 稀疏向量
程序员文章站
2024-03-17 21:39:10
...
CSP 202006-2
题目
#include <iostream>
#include <vector>
using namespace std;
typedef struct {
long long i, val;
}Point;
long long n, a, b;
int main() {
ios::sync_with_stdio(false);
//读入数据
cin >> n >> a >> b;
vector<Point> p1, p2;
for (long long i = 0; i < a; i++) {
Point t;
cin >> t.i >> t.val;
p1.push_back(t);
}
for (long long i = 0; i < b; i++) {
Point t;
cin >> t.i >> t.val;
p2.push_back(t);
}
//处理
long long i = 0, j = 0, val = 0, p1s = p1.size(), p2s = p2.size();
while (i < p1s && j < p2s) {
if (p1[i].i == p2[j].i) {
val += p1[i].val * p2[j].val;
i++;
j++;
}
else if (p1[i].i < p2[j].i) {
i++;
}
else {
j++;
}
}
cout << val;
return 0;
}
上一篇: WEEK16 csp模拟 宇宙狗的危机