您的位置:首页 > 其它

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++完整代码如下:

这里写代码片
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PAT甲级