-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA1009.cpp
56 lines (56 loc) · 1.02 KB
/
A1009.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
46
47
48
49
50
51
52
53
54
55
56
#include<cstdio>
#include<cstring>
int main()
{
double exponents[1001];
double results[2001];
memset(results, 0, sizeof(results));
memset(exponents, 0, sizeof(exponents));
//printf("%lf %.1lf\n", exponents[0], exponents[1]);
int n, count = 0;
scanf("%d", &n);
while (n)
{
int exp;
double coe;
scanf("%d%lf", &exp, &coe);
//printf("%d%lf\n", exp, coe);
exponents[exp] += coe;
n--;
}
//printf("%lf %.1lf\n", exponents[0], exponents[1]);
scanf("%d", &n);
while (n)
{
int exp;
double coe;
scanf("%d%lf", &exp, &coe);
for (int i = 0; i < 1001; i++)
{
results[i + exp] += exponents[i] * coe;
}
n--;
}
for (int i = 0; i <= 2000; i++)
{
if (results[i] != 0)
count++;
}
if (count == 0)
printf("0");
else
printf("%d ", count);
int step = 1;
for (int i = 2000; i >= 0; i--)
{
if (results[i] != 0 && step != count)
{
printf("%d %.1lf ", i, results[i]);
step++;
}
else if (results[i] != 0 && step == count)
printf("%d %.1lf", i, results[i]);
}
printf("\n");
return 0;
}