当前位置:网站首页>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;
}
边栏推荐
- YOLOv5s-ShuffleNetV2
- Master the use of auto analyze in data warehouse
- Niuke Xiaobai month race 7 who is the divine Archer
- 在线文本行固定长度填充工具
- QT realizes interface sliding switching effect
- How to use async Awati asynchronous task processing instead of backgroundworker?
- Swagger突然发癫
- 2021 Hefei informatics competition primary school group
- 欧拉函数
- 92. (cesium chapter) cesium building layering
猜你喜欢

用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
牛客小白月赛7 谁是神箭手

BCG 使用之CBCGPProgressDlg进度条使用

Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples

一文掌握数仓中auto analyze的使用

Euler function

Pointnet/Pointnet++点云数据集处理并训练

Stream stream

PointNeXt:通过改进的模型训练和缩放策略审视PointNet++

黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
随机推荐
Educational Codeforces Round 22 E. Army Creation
PolyFit软件介绍
HDU 6440 2018 Chinese college student program design network competition
Cbcgpprogressdlgctrl progress bar used by BCG
The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
牛客小白月赛7 E Applese的超能力
LM10丨余弦波动顺势网格策略
Niuke Xiaobai month race 7 who is the divine Archer
JVM系列之对象的创建
Unity editor extends C to traverse all pictures in folders and subdirectories
The 300th weekly match of leetcode (20220703)
偏移量函数及开窗函数
1008 elevator (20 points) (PAT class a)
有关架构设计的个人思考(本文后续不断修改更新)
YOLOv5s-ShuffleNetV2
指定输出的字符集
Socket programming demo II
1005 spell it right (20 points) (pat a)
牛客小白月赛7 I 新建 Microsoft Office Word 文档
1003 emergency (25 points) (PAT class a)