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. Day 6-1计算机网络基础&TCP/IP

    按照功能不同,人们将互联网协议分为osi七层或tcp/ip五层或tcp/ip四层(我们只需要掌握tcp/ip五层协议即可) 每层运行常见物理设备: TCP/IP协议: Transmission Con ...

  2. 使用PHP进行SOCKET编程

    一.SOCKET原理图 二.SOCKET常用函数 1.创建socket函数: resource socket_create ( int $domain , int $type , int $proto ...

  3. supervisor /var/run/supervisor/supervisor.sock not found 或者/tmp/supervisor.sock not found

    刚按装完supervisor,这时候用supervisorctr -c supervisor.conf 会报错: /var/run/supervisor/supervisor.sock not fou ...

  4. HTML中文本过长时自动隐藏末尾部分或中间等任意部分

    一.    一般情况下,HTML字符串过长时都会将超过的部分隐藏点,方法如下: 设置CSS: .ellipsis-type{ max-width: 50px;                      ...

  5. 1.docker 数据卷的备份和恢复(非大数据量)

    在生产环境中使用 Docker,很多时候需要对数据进行持久化,或者进行容器间的数据共享. 容器中的管理数据主要有两种方式: 数据卷 (Data Volumes): 容器内数据直接映射到本地主机环境: ...

  6. endnote中文格式“,等”的修改

    https://www.howsci.com/endnote-eng-cn-refer-etal.html

  7. cuda编程视频资料

    胡文美教授 http://www.gpuworld.cn/article/show/463.html

  8. P1020 导弹拦截

    思路:贪心思路 拿比飞来的导弹高并且高度和飞来的导弹最相近的拦截系统去接, 如果全部都比导弹矮,那就新开一个拦截系统 #include<cstdio> #include<string ...

  9. tp5 日志管理

    日志驱动 日志可以通过驱动支持不同的方式写入,默认日志会记录到文件中,系统已经内置的写入驱动包括 File.Socket,如果要临时关闭日志写入,可以设置日志类型为Test即可,例如: 'log' = ...

  10. flowable6.4.1+springboot使用dmn

    resources/dmn/strings_1.dmn <?xml version="1.0" encoding="UTF-8"?> <def ...