【1009】Product of Polynomials (25 分)

简介: 【1009】Product of Polynomials (25 分)【1009】Product of Polynomials (25 分)
#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;   
}
相关文章
|
3天前
|
SQL Java 数据库连接
基于QueryWrapper的查询,查询出名字中带有o的,存款大于等于1000元的人的id、username、info、balance字段
基于QueryWrapper的查询,查询出名字中带有o的,存款大于等于1000元的人的id、username、info、balance字段
|
2月前
|
监控 数据挖掘 定位技术
Spartacus 测试,后台修改 product price 数据后,添加到 Cart 时,会带出来最新的价格吗
Spartacus 测试,后台修改 product price 数据后,添加到 Cart 时,会带出来最新的价格吗
PAT甲级 1009. Product of Polynomials (25分)
PAT甲级 1009. Product of Polynomials (25分)
55 0
【1016】Phone Bills (25 分)
【1016】Phone Bills (25 分) 【1016】Phone Bills (25 分)
87 0
【1041】Be Unique (20 分)
【1041】Be Unique (20 分) 【1041】Be Unique (20 分)
81 0
【1139】First Contact (30分)
【1139】First Contact (30分) 【1139】First Contact (30分)
63 0
【1126】Eulerian Path (25分)【连通图】
1)如果是一个连通图,则只需要一次DFS即可完成遍历。 (2)可以用DFS判断一个无向图是否
142 0
【1083】List Grades (25 分)
【1083】List Grades (25 分) 【1083】List Grades (25 分)
88 0
【1109】Group Photo (25分)【双端队列/逻辑】
【1109】Group Photo (25分)【双端队列/逻辑】 【1109】Group Photo (25分)【双端队列/逻辑】
91 0
【1116】Come on! Let's C (20分)【简单逻辑 set】
【1116】Come on! Let's C (20分)【简单逻辑 set】 【1116】Come on! Let's C (20分)【简单逻辑 set】
93 0