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
 #include<cstdio>
#include<iostream>
using namespace std;
int main(){
int K, n, count = ;
double a, poly1[] = {}, re[] = {};
scanf("%d", &K);
for(int i = ; i < K; i++){
scanf("%d%lf", &n, &a);
poly1[n] = a;
}
scanf("%d", &K);
for(int i = ; i < K; i++){
scanf("%d%lf", &n, &a);
for(int j = ; j < ; j++)
re[n + j] = re[n + j] + poly1[j] * a;
}
for(int i = ; i >= ; i--){
if(re[i] != )
count++;
}
printf("%d", count);
for(int i = ; i >= ; i--){
if(re[i] != )
printf(" %d %.1lf", i, re[i]);
}
cin >> K;
return ;
}

总结:

1、指数为1000的多项式乘法,结果最高为2000次幂。

2、为减少时间复杂度,可以将第一个多项式存储,第二个不存。第二个多项式边读入边直接遍历poly1并做乘法。还可以将两个多项式的系数与指数分别开数组存下来以减小复杂度。

A1009. Product of Polynomials的更多相关文章

  1. A1009 Product of Polynomials (25)(25 分)

    A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...

  2. PAT A1009 Product of Polynomials (25 分)——浮点,结构体数组

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

  3. PAT甲级——A1009 Product of Polynomials

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

  4. PAT A1009 Product of Polynomials(25)

    课本AC代码 #include <cstdio> struct Poly { int exp;//指数 double cof; } poly[1001];//第一个多项式 double a ...

  5. 1009 Product of Polynomials (25 分)

    1009 Product of Polynomials (25 分) This time, you are supposed to find A×B where A and B are two pol ...

  6. PAT1009:Product of Polynomials

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  7. 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 p ...

  8. PTA (Advanced Level) 1009 Product of Polynomials

    1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...

  9. PAT Product of Polynomials[一般]

    1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...

随机推荐

  1. 对于修改jsp页面后页面不发生变化的解决方法

    1.清除 Tomcat 6.0\work\Catalina\localhost 里面这个工程的内容:2.清除 Tomcat 6.0 webapps 里面的这个工程内容,然后重新部署,重启服务器:3.清 ...

  2. WPF设置软件界面背景为MediaElement并播放视频

    在我们的常见的软件界面设计中我们经常会设置软件的背景为SolidColorBrush或者LinerColorBrush.RadialGradientBrush 等一系列的颜色画刷为背景,有时我们也会使 ...

  3. Python turtle绘制阴阳太极图代码解析

    本文详细分析如何使用Python turtle绘制阴阳太极图,先来分解这个图形,图片中有四种颜色,每条曲线上的箭头表示乌龟移动的方向,首先从中心画一个半圆(红线),以红线所示圆的直径作半径画一个校园, ...

  4. 莫烦theano学习自修第六天【回归】

    1. 代码实现 from __future__ import print_function import theano import theano.tensor as T import numpy a ...

  5. Django数据库操作中You are trying to add a non-nullable field 'name' to contact without a default错误处理

    name = models.CharField(max_length=50) 执行:python manage.py makemirations出现以下错误: You are trying to ad ...

  6. spring和junit整合

  7. workerman——配置小程序的wss协议

    前言 服务器: 阿里云服务器 | 需要在安全组放开443端口和workerman需要的端口 环境: oneinstack | lnmp oneinstack添加虚拟主机的时候选择第三个即可 | 这个添 ...

  8. Python中的numpy模块解析

    numpy 1.  创建对象 维度(dimensions):轴 轴的个数:秩(rank) Numpy最重要的一个特点就是其N维数组对象(即ndarray) 创建数组最简单的函数就是用array函数: ...

  9. DNS 透明代理

    DNS 透明代理 一.使用DNS负载均衡虚拟服务器(DNS * 53)的方式 --- 推荐使用的方式 注意:只会代理跨内网网段的DNS查询请求 ---------------------------- ...

  10. MT【265】a+b,ab

    已知$a+b=1$,求$(a^3+1)(b^3+1)$的最大值_____ $(a^3+1)(b^3+1)=a^3+b^3+a^3+b^3+1$ $=(a+b)^3(a^2+b^2-ab)+a^3b^3 ...