1009_Product of Polynomials (25分)[模拟]
Posted niboss
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1009_Product of Polynomials (25分)[模拟]相关的知识,希望对你有一定的参考价值。
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分)[模拟]的主要内容,如果未能解决你的问题,请参考以下文章
PTA 甲 1009 Product of Polynomials
PAT1009:Product of Polynomials