美文网首页
1009 Product of Polynomials (25

1009 Product of Polynomials (25

作者: 79d12e22ec53 | 来源:发表于2019-07-31 10:11 被阅读0次
    #include <iostream>
    #include <stdio.h>
    
    typedef struct Poly {
        int exp; //指数
        double cof; //系数 
    }Poly;
    
    
    
    int main(int argc, char *argv[]) {
        Poly poly[1001];
        double ans[2001];
        
        int n;
        scanf("%d", &n); //第一个多项式项数 
        for(int i=0; i<n; i++) {
            scanf("%d %lf", &poly[i].exp, &poly[i].cof);
        }
        
        int m;
        scanf("%d", &m);
        for(int i=0; i<m; i++) {
            int exp;
            double cof;
            scanf("%d %lf", &exp, &cof);
            
            for(int j=0; j<n; j++) {
                ans[exp + poly[j].exp] += (cof * poly[j].cof);
            }
        }
        
        int count = 0;
        for(int i=0; i<=2000; i++) {
            if(ans[i] != 0.0) count++;
        }
        printf("%d", count);
        for(int i=2000; i>=0; i--) {
            if(ans[i] != 0.0) {
                printf(" %d %.1lf", i, ans[i]);
            }
        }
        
    }
    
    

    相关文章

      网友评论

          本文标题:1009 Product of Polynomials (25

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