标签:25 Product nk PAT int 多项式 cin k2 k1
题目描述:
This time, you are supposed to find A×B where A and B are two polynomials.
Input Specification:
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<iostream>
using namespace std;
double nk,a[1010] = {0.0},c[2020]={0.0}; // nk 系数 数组下标 次数
int main()
{
int k1,k2,sum=0,n;
cin >> k1;
for(int i = 0 ; i < k1 ; i++)
{
cin >> n >> nk ;
a[n] = nk ;
}
cin >> k2;
for(int i = 0 ; i < k2 ; i++)
{
cin >> n >> nk ;
for(int j = 0 ; j <= 1000 ; j++ )
c[ n + j ] += nk * a[j] ;
}
for(int i = 0 ; i <= 2000 ; i++ )
if(c[i])
sum++;
cout << sum ;
for(int i = 2000 ; i >= 0 ; i-- )
if(c[i])
printf(" %d %.1lf", i, c[i]);
return 0;
}
标签:25,Product,nk,PAT,int,多项式,cin,k2,k1 来源: https://www.cnblogs.com/yztozju/p/16580454.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。