-
Notifications
You must be signed in to change notification settings - Fork 0
/
1009.cpp
45 lines (36 loc) · 858 Bytes
/
1009.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <cstdio>
const int MAXN = 2000 + 10;
double poly1[MAXN], poly2[MAXN];
double ans[MAXN];
int main() {
int k1;
scanf("%d", &k1);
for (int i = 0; i < k1; i++) {
int x;
scanf("%d", &x);
scanf("%lf", &poly1[x]);
}
int k2;
scanf("%d", &k2);
for (int i = 0; i < k2; i++) {
int x;
scanf("%d", &x);
scanf("%lf", &poly2[x]);
}
for (int i = 0; i <= 1000; i++) {
for (int j = 0; j <= 1000; j++) {
if (poly1[i] != 0 && poly2[j] != 0) {
ans[i + j] += poly1[i] * poly2[j];
}
}
}
int cnt = 0;
for (int i = 0; i <= 2000; i++) {
if (ans[i] != 0) cnt++;
}
printf("%d", cnt);
for (int i = 2000; i >= 0; i--) {
if (ans[i] != 0) printf(" %d %.1lf", i, ans[i]);
}
return 0;
}