0
点赞
收藏
分享

微信扫一扫

【1009】Product of Polynomials (25 分)

RJ_Hwang 2022-07-14 阅读 35


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
using namespace std;
struct Poly{
int exp; //指数
double cof;//系数
}poly[1001]; //第一个多项式

double ans[2001];

int main(){
int n,m,number=0;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d %lf",&poly[i].exp,&poly[i].cof);
}
scanf("%d",&m);
for(int i=0;i<m;i++){
int exp;
double cof;
scanf("%d %lf",&exp,&cof);
for(int j=0;j<n;j++){ //与第一个多项式中的每一项相乘
ans[exp+poly[j].exp]+=(cof*poly[j].cof);
//核心步骤!!!!!!!
}
}
for(int i=0;i<=2000;i++){
if(ans[i]!=0.0) number++; //统计非零系数的项数
}
printf("%d",number);
for(int i=2000;i>=0;i--){
if(ans[i]!=0.0){
printf(" %d %.1f",i,ans[i]);
}
}
system("pause");
return 0;
}

 

举报

相关推荐

0 条评论