PAT A1009 Product of Polynomials (25)
来源:互联网 发布:免费下载圈点软件 编辑:程序博客网 时间:2024/05/16 15:56
题目地址:https://www.patest.cn/contests/pat-a-practise/1009
题目描述:
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
题意:
给出两个多项式的系数,求这两个多项式的乘积。
解题思路:
先获得第一个多项式的系数,然后再输入第二个系数时循环与第一个多项式的系数相乘,并将结果加到对应指数的系数上,最后得到要输出的所有非零系数的项。
注意点:
- 答案的系数数组要至少开到 2001,因为两个最高幂次为 1000 的多项式相乘,最高幂次可以达到 2000
- 没有必要开两个数组存放两个多项式,然后读完系数之后再处理,只需要第二个多项式的系数边读入边处理
- 系数是从大到小输出。
- 只需要输出非零系数的项。
C++完整代码如下:
这里写代码片
- PAT A1009 Product of Polynomials (25)
- 【PAT】A1009. Product of Polynomials (25)
- PAT---A1009. Product of Polynomials (25)
- PAT A1009. Product of Polynomials (25)
- PAT A1009 Product of Polynomials(25)
- PAT A1009 Product of Polynomials
- PAT A1009. Product of Polynomials
- A1009 Product of Polynomials (25)
- PAT-A1009 Product of Polynomials (25)(模拟)
- PAT A1009. Product of Polynomials(多项式乘法)
- 1009. Product of Polynomials (25)-PAT
- 【PAT】1009. Product of Polynomials (25)
- (PAT)1009. Product of Polynomials (25)
- PAT 1009. Product of Polynomials (25)
- PAT A 1009. Product of Polynomials (25)
- PAT 1009. Product of Polynomials (25)
- PAT 1009. Product of Polynomials (25)
- PAT 1009. Product of Polynomials (25)
- 《linux学习》之网络相关
- 树的创建与遍历 叶子数 与深度
- android5.1系统修改源码实现隐藏底部状态栏、隐藏通知栏、隐藏上方状态栏、永不熄屏的方法
- 嵌入式开发12天(虚拟机的环境配置,目录的快捷方式,交叉编译工具的安装,tftp的安装,nfs的安装)
- poj 2318 toys 计算几何+二分
- PAT A1009 Product of Polynomials (25)
- Android Camera 使用小结
- 回归本源,勿忘初心,趋势与未来洞察
- HDOJ 1290 献给杭电五十周年校庆的礼物
- warning: escape sequence 'u' is not valid. see 'help sprintf' for valid escape sequences._
- c# 操作dbf文件时,出现“command contains unrecognized phrase keyword” 的问题
- android 开发工具—AndroidStudio获取SHA1值
- Android跑马灯实现
- 局部变量与成员变量的存放