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 N​1​​ a​N​1​​​​ N​2​​ a​N​2​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤N​K​​<⋯<N​2​​<N​1​​≤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

25分:

注意:

1.注意指数最大会到2000, C数组应该开到2001

#include <iostream>
#include <cmath>
using namespace std;int ka, kb; //A和B中的非零项个数
double A[1001] = {0.0}, B[1001] = {0.0}, C[2001] = {0.0};
int expon;
double coe;  //指数和系数
int mxa = -1, mxb = -1;int main()
{scanf("%d", &ka);for(int i = 0; i < ka; i++){scanf("%d %lf", &expon, &coe);A[expon] += coe;mxa = max(mxa, expon);}scanf("%d", &kb);for(int i = 0; i < kb; i++){scanf("%d %lf", &expon, &coe);B[expon] += coe;mxb = max(mxb, expon);}for(int i = 0; i <= mxa; i++){for(int j = 0; j <= mxb; j++){if(A[i] != 0 && B[j] != 0){C[i+j] += A[i] * B[j];}}}int ct = 0;for(int i = 2000; i >= 0; i--){if(C[i] != 0) ct++;}printf("%d", ct);for(int i = 2000; i >= 0; i--){if(C[i] != 0) printf(" %d %.1f", i, C[i]);}return 0;
}

2.柳神计算时输入多项式B时直接进行计算!参考:

#include <iostream>
using namespace std;
int main() {int n1, n2, a, cnt = 0;scanf("%d", &n1);double b, arr[1001] = {0.0}, ans[2001] = {0.0};for(int i = 0; i < n1; i++) {scanf("%d %lf", &a, &b);arr[a] = b;}scanf("%d", &n2);for(int i = 0; i < n2; i++) {scanf("%d %lf", &a, &b);for(int j = 0; j < 1001; j++)ans[j + a] += arr[j] * b;}for(int i = 2000; i >= 0; i--)if(ans[i] != 0.0) cnt++;printf("%d", cnt);for(int i = 2000; i >= 0; i--)if(ans[i] != 0.0)printf(" %d %.1f", i, ans[i]);return 0;
}

PAT甲级 -- 1009 Product of Polynomials (25 分)相关推荐

  1. PAT甲级1009 Product of Polynomials (25分)

    PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...

  2. PAT甲级1009 Product of Polynomials:[C++题解]多项式乘法、高精度乘法

    文章目录 题目分析 题目链接 题目分析 多项用一个数组来表示,数组下标表示多项式的次幂,存的内容表示多项式的系数. 然后用两重循环来计算多项式的乘法: for i : 第二个式子for j:第一个式子 ...

  3. 【测试点0分析】1009 Product of Polynomials (25 分)

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 This time, you are supposed to find A×B where A and B are two pol ...

  4. 【PAT甲级 多项式相乘】1009 Product of Polynomials (25 分) C++ 全部AC

    题目 思路 维护三个数组: arrA[1001]存储第一行数据 arrB[1001]存储第二行数据 c[1000000]存储计算结果 数组下标表示多项式的指数,数组存的内容表示多项式的系数 将arrA ...

  5. 【PAT】1009. Product of Polynomials (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...

  6. 1009 Product of Polynomials (25 分)【难度: 简单 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805509540921344 注意:系数数据范围虽然是0-1000 但是乘 ...

  7. 17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼

    题目 After each PAT, the PAT Center will announce the ranking of institutions based on their students' ...

  8. PAT甲级-1021 Deepest Root(25分)

    题目:1021 Deepest Root(25分) 分析:找出以某个节点为根时,最深的根,这题可能会超时要用vector来表示二维数组 疑问:代码一是第二次写的超时了,代码二是第一次写的AC了,找不出 ...

  9. PAT甲级--1007 Maximum Subsequence Sum (25 分)

    题目详情 - 1007 Maximum Subsequence Sum (25 分) (pintia.cn) Given a sequence of K integers { N1​, N2​, .. ...

最新文章

  1. 详解Ubuntu10.10下Qt连接Mysql数据库
  2. AlarmManager与PendingIntent的联合使用(一)
  3. 第十章—DOM(0)—NODE类型
  4. 九度oj 题目1376:最近零子序列
  5. Node提示:error code Z_BUF_ERROR,error error -5,error zlib:unexpected end of file
  6. 高等数学下-赵立军-北京大学出版社-题解-练习10.5
  7. [C++ rudiment][转]typedef 使用
  8. centos mysql安装
  9. 医院计算机科学与技术笔试试题,医院信息科招收计算机科学与技术专业的笔试试题...
  10. redis操作之迭代器 hscan
  11. CAD手机端怎么将DWG格式的图纸文件转换成PDF格式?
  12. 【社区周会】2021-04-27 内容概要
  13. 一个安全删除文件的shell命令
  14. 中国企业数智化价值不高,主要是因为三个问题
  15. Matplotlib做动图(基础版)
  16. 分享Android单元测试
  17. 打印输入的字符串(C语言)
  18. 小米AI实验室入选《麻省理工科技评论》中国“2021人工智能创新研究院”
  19. php 数据库编码,如何在php和mysql数据库中正确编码字符
  20. c语言时钟程序整点报时,单片机开发的(带整点报时、音乐闹钟)电子时钟(一)...

热门文章

  1. 短视频时代不可忽视的幕后功臣竟然是它!
  2. Linux网络编程 | 信号 :信号函数、信号集、统一事件源 、网络编程相关信号
  3. 某瓜数据之sign参数分析
  4. Python selenium对js元素进行增删改查操作
  5. Python练习题14
  6. C++中的继承(三)
  7. 【LiveVideoStack线上分享】— 视频生产环境下的音视频解决方案
  8. 一文入门 Kafka
  9. TEG《选择》乘风破浪 · 披荆斩棘
  10. nginx 源码学习笔记(十)——基本容器——ngx_hash