码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-12-27 00:20:33      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:cstring   cto   ima   out   ons   最大   queue   color   memset   

技术图片

 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分)[模拟]

标签:cstring   cto   ima   out   ons   最大   queue   color   memset   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!