当前位置:网站首页>1009 product of polynomials (25 points) (PAT class a)
1009 product of polynomials (25 points) (PAT class a)
2022-07-04 19:37:00 【Acacia moon tower】
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
Multiplication of polynomials .
#include <iostream>
using namespace std;
int main() {
int n1, n2, a, cnt = 0;
scanf("%d", &n1);
double b, arr[1001] = {0.0}, ans[2001] = {0.0};
for(int i = 0; i < n1; i++) {
scanf("%d %lf", &a, &b);
arr[a] = b;
}
scanf("%d", &n2);
for(int i = 0; i < n2; i++) {
scanf("%d %lf", &a, &b);
for(int j = 0; j < 1001; j++)
ans[j + a] += arr[j] * b;
}
for(int i = 2000; i >= 0; i--) {
if(ans[i] != 0.0) {
cnt++;
}
}
printf("%d", cnt);
for(int i = 2000; i >= 0; i--) {
if(ans[i] != 0.0) {
printf(" %d %.1f", i, ans[i]);
}
}
return 0;
}
边栏推荐
猜你喜欢

记一次 .NET 某工控数据采集平台 线程数 爆高分析

Introduction to polyfit software

HMM隐马尔可夫模型最详细讲解与代码实现

黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
Some thoughts on whether the judgment point is located in the contour

Stream流

Detailed explanation of the binary processing function threshold() of opencv

BCG 使用之CBCGPProgressDlg进度条使用

Master the use of auto analyze in data warehouse

OpenCV的二值化处理函数threshold()详解
随机推荐
1005 Spell It Right(20 分)(PAT甲级)
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
An example of multi module collaboration based on NCF
线上数据库迁移的几种方法
黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
HDU 6440 2018中国大学生程序设计网络选拔赛
1009 Product of Polynomials(25 分)(PAT甲级)
Wechat reading notes of "work, consumerism and the new poor"
1011 World Cup betting (20 points) (pat a)
1011 World Cup Betting (20 分)(PAT甲级)
Shell 编程核心技术《三》
The kth largest element in the array
《工作、消费主义和新穷人》的微信读书笔记
TCP两次挥手,你见过吗?那四次握手呢?
JVM系列之对象的创建
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
有关架构设计的个人思考(本文后续不断修改更新)
函数式接口
Several methods of online database migration
1006 Sign In and Sign Out(25 分)(PAT甲级)