难在有几个单词不认识,要靠测试用例猜。
#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);
}
本文介绍了一种通过测试用例辅助解决编程中遇到词汇理解难题的方法,特别关注于C++代码中节点结构的处理。通过输入输出操作,展示了如何利用map结构存储并计算特定条件下的数据加权求和。
157

被折叠的 条评论
为什么被折叠?



