1009

作者: 祎歆 | 来源:发表于2018-08-02 15:09 被阅读0次

1009 Product of Polynomials (25)(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: K N1 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10, 0 <= NK < ... < N2 < N1 <=1000.

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

这个问题有一个小坑,小数部分0.45的时候浮点表示为0.4499999999
牛客网会约成0.4

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int a,b;
    double x[2][110]={},y[2][110]={},z[3001]={};
    cin>>a;
    for (int i=0;i<a;i++){
        cin>>x[0][i]>>x[1][i];
    }
    cin>>b;
    for (int i=0;i<b;i++){
        cin>>y[0][i]>>y[1][i];
    }
    int c,n=0;
    double d;
    for (int i=0;i<a;i++){
        for (int j=0;j<b;j++){
            c=x[0][i]+y[0][j];
            d=x[1][i]*y[1][j];
            if (z[c]!=0)n--;
            z[c]+=d;
            if (z[c]!=0)n++;
        }
    }
    cout<<n;
    for (int i=3000;i>=0;i--){
        if (z[i]!=0){
            printf(" %d %0.1f",i,z[i]);
        }
    }

}

相关文章

  • 1009次被拒绝

    1009 Rejections1009次被拒绝 Once, there was an old man, who w...

  • 看起来很好吃^_^

    坚持分享第1009天 20201128

  • 1009

    //1009 说反话 (20)(20 分)//给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。////...

  • 1009

    1009 Product of Polynomials (25)(25 分)This time, you are ...

  • 1009

    一点点心得,和人合作,先小人后君子,高要求高标准,因为往往对方只能达到你要求的百分之60。同事之间和你平级或者比你...

  • 1009

    想着生活里改变一些东西自然会好一些, 是我太天真啦 每日仍有固定10-30分钟时间 不想活的时刻 户外运动 回复信...

  • 1009

  • 1009

    今天认识了LR,她跟我想的不一样,看过她的空间,觉得她是那种敢想敢做,无拘无束的女生。今天见了之后才觉得,看似乖乖...

  • 1009

    早上好!#幸福实修#~每天进步1%#幸福实修12班@吕敏一富阳 20171009(14/30) 【幸福三朵玫瑰】 ...

  • 1009

    无比欢喜,自己原来已经收藏了这期GQ的7周年特别刊。心底里爱这位主编,这所谓的爱,是那种故人,完全是我能够通灵的逻...

网友评论

      本文标题:1009

      本文链接:https://www.haomeiwen.com/subject/ydxsvftx.html