zoukankan      html  css  js  c++  java
  • PAT 1009 Product of Polynomials

    1009 Product of Polynomials (25 分)
     

    This time, you are supposed to find A×B where A and B are two polynomials.

    Input Specification:

    Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:

    N1​​ aN1​​​​ N2​​ aN2​​​​ ... NK​​ aNK​​​​

    where K is the number of nonzero terms in the polynomial, Ni​​ and aNi​​​​ (,) are the exponents and coefficients, respectively. It is given that 1, 0.

    Output Specification:

    For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.

    Sample Input:

    2 1 2.4 0 3.2
    2 2 1.5 1 0.5
    

    Sample Output:

    3 3 3.6 2 6.0 1 1.6
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define maxnum 100005
    
    double a[1005] = {0};
    double b[1005] = {0};
    double c[maxnum] = {0};
    
    
    int main(){
        int n;cin >> n;
        int t;
        for(int i=0;i < n;i++){
            int x;double y;
            cin >> x >> y;
            a[x] = y;
            if(!i)t = x;
        }
        int m;cin >> m;
        int start;
        for(int i=0;i < m;i++){
            int x;double y;
            cin >> x >> y;
            b[x] = y;
            if(!i) start = x;
        }
    
        for(int i=0;i < t+5;i++){
            for(int j=0;j < start+5;j++){
                c[i+j] += a[i]*b[j];
            }
        }
    
        int cnt = 0;
        for(int i=0;i < maxnum;i++)if(c[i])cnt++;
        cout << cnt;
    
        for(int i=maxnum-1;i>=0;i--){
            if(c[i]) printf(" %d %.1lf",i,c[i]);
        }
    
    
        return 0;
    }

    空间开的有点小炸,做了一下优化就好了,再一次理解错了提议,K<10,不一定就项系数<10,还好这题没出毒瘤卡边界数据,在超过1e5的地方直接放弃了。。

     
  • 相关阅读:
    PC-BSD 9.2 发布,基于 FreeBSD 9.2
    Attic 0.8.1 发布,备份程序
    Apache Lucene 4.5 发布,Java 搜索引擎
    Linux Kernel 3.11.4/3.10.15/3.4.65/3.0.99
    Lucene 查询工具 LQT
    Rubinius 2.0 发布,Ruby 虚拟机
    Golang通过Thrift框架完美实现跨语言调用
    微软再次要求Google审查官方链接 称将进行调查
    TCPDF 6.0.036 发布,PHP 的 PDF 操作包
    libnode 0.4.0 发布,C++ 语言版的 Node.js
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10680840.html
Copyright © 2011-2022 走看看