PAT A1009 Product of Polynomials (25)
2016-07-25 11:08
411 查看
题目地址: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++完整代码如下:
题目描述:
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甲级.1042. Shuffling Machine (20)
- PAT A1011 World Cup Betting (20)
- PAT A1042 Shuffling Machine (20)
- PAT A1046 Shortest Distance (20)
- PAT A1065 A+B and C (64bit) (20)
- PAT A1002 A+B for Polynomials (25)
- PAT(甲级) 1010. Radix (25)
- PAT(甲级) 1007. Maximum Subsequence Sum (25)
- PAT(甲级) 1002. A+B for Polynomials
- PAT甲级 1002. A+B for Polynomials (25)
- PAT甲级 1025
- PAT甲级 1024
- PAT甲级 1023
- PAT甲级 1022
- PAT甲级 1021 没有AC,留着重做
- PAT甲级 1020
- PAT甲级 1019
- PAT甲级 1018 没有AC,也不想重做这题
- PAT甲级 1017
- PAT甲级 1016