首页 > 其他 > 详细

1009_Product of Polynomials (25分)[模拟]

时间:2019-12-26 23:58:09      阅读:134      评论:0      收藏:0      [点我收藏+]

技术分享图片

 1 #include<iostream>
 2 #include<vector>
 3 #include<queue>
 4 #include<map>
 5 #include<set>
 6 #include<cmath>
 7 #include<cstdio>
 8 #include<cstdlib>
 9 #include<cstring>
10 #include<algorithm>
11 using namespace std;
12 const int  maxLen = 1000 + 10;
13 
14 int K, maxRes, maxN, p;//maxNum记录结果的最大次数
15 double N[maxLen], res[maxLen * maxLen], pVal;
16 
17 int main()
18 {
19     memset(N, 0, sizeof(N));
20     memset(res, 0, sizeof(res));
21     maxN = maxRes = 0; 
22     map<int, double> map;
23 
24     cin >> K;
25     for (int i = 0; i < K; i++) {
26         cin >> p;
27         cin >> N[p];
28         maxN = max(maxN, p);
29     }
30 
31     cin >> K;
32     for (int i = 0; i < K; i++) {
33         cin >> p >> pVal;
34         for (int i = 0; i <= maxN; i++) {
35             if (N[i] != 0) {
36                 res[i + p] += N[i] * pVal;
37                 maxRes = max(maxRes, i + p);
38             }
39         }
40     }
41     for (int i = maxRes; i >= 0; i--) {
42         if (res[i] != 0) {
43             map[i] = res[i];
44         }
45     }
46     cout << map.size();
47     for (auto iter = map.rbegin(); iter != map.rend(); iter++) {
48         printf(" %d %.1lf", iter->first, iter->second);
49     }
50     return 0;
51 }

1009_Product of Polynomials (25分)[模拟]

原文:https://www.cnblogs.com/NiBosS/p/12104992.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!