难在有几个单词不认识,要靠测试用例猜。
#include <bits/stdc++.h>
using namespace std;
struct node {
int e;
double a;
};
vector<node> v, ans;
map<int, double> mp;
int main () {
int k, e;
double a;
scanf ("%d", &k);
for (int i = 0; i < k; i++) {
scanf ("%d %lf", &e, &a);
v.push_back(node{e, a});
}
scanf ("%d", &k);
for (int i = 0; i < k; i++) {
scanf ("%d %lf", &e, &a);
for (auto it : v) mp[it.e + e] += a * it.a;
}
for (auto it : mp)
if (it.second != 0.0) ans.push_back(node{it.first, it.second});
cout << ans.size();
for (int i = ans.size() - 1; i >= 0; i--)
printf (" %d %.1lf", ans[i].e, ans[i].a);
}
|