zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    Python3 循环语句
    Python3 条件控制
    Python3 字典
    Python3 元组
    Python的字符串函数
    2019/10/24
    JS-字符串方法总结
    maven环境变量配置
    PowerDesigner逆向导入MYSQL数据库并显示中文注释(转载)
    web_custom_request函数详解(转载)
  • 原文地址:https://www.cnblogs.com/NiBosS/p/12104992.html
Copyright © 2011-2022 走看看