PAT A 1009. Product of Polynomials (25)
1WA 系数为0不能算
2WA 虽然系数为0不算还是算在了K里面
3WA 智障 样例都没过就交了 可能有多种组合达到相同次数 用+= 而不是 =
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, double> Pair;
const double eps = 1e-9;
int main()
{
vector<Pair> v[2];
for (int i = 0; i < 2; i++) {
int k;
scanf("%d", &k);
while (k--) {
int ni;
double ani;
scanf("%d%lf", &ni, &ani);
v[i].push_back(make_pair(ni, ani));
}
}
map<int, double> mp;
for (auto x1 : v[0])
for (auto x2 : v[1])
mp[x1.first + x2.first] += x1.second * x2.second;
vector<Pair> ans;
for (auto it = mp.rbegin(); it != mp.rend(); it++) {
auto e = *it;
if (abs(e.second) < eps) {
continue;
}
ans.push_back(e);
}
cout << ans.size();
for (auto e : ans)
printf(" %d %.1f",e.first, e.second);
cout << endl;
}