题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805509540921344
AC代码:关于测试点1,3
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 1010;
float A[maxn],B[maxn],res[maxn+maxn];
//底数值一律换成float型存储,否则,测试点1,3通不过
int main() {
int n1,n2;
cin >> n1;
for (int i = 0; i < n1; i++) {
int exp;
float cof;
cin >> exp>>cof;
A[exp] = cof;
}
cin >> n2;
for (int i = 0; i < n2; i++) {
int exp;
float cof;
cin >> exp >> cof;
B[exp] = cof;
}
for (int i = 0; i < maxn; i++) {
if (A[i] != 0) {
for (int j = 0; j < maxn; j++) {
if (B[j] != 0) {
res[i + j] += A[i] * B[j];
}
}
}
}
int cnt = 0;
float t = 0.05;
for (int i = 0; i < maxn * 2; i++) {
if (abs(res[i])>=t) {
cnt++;
}
}
printf("%d",cnt);
for (int i = maxn*2; i >=0; i--) {
if (abs(res[i]) >= t) {
if (cnt) {
printf(" ");
cnt -= 1;
}
printf("%d %.1f",i,res[i]);
}
}
return 0;
}