当前位置:网站首页>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;
}
边栏推荐
- 1008 Elevator(20 分)(PAT甲级)
- Add namespace declaration
- 明明的随机数
- Shell 编程核心技术《一》
- kotlin 基本使用
- 1007 maximum subsequence sum (25 points) (PAT class a)
- Introduction to polyfit software
- Shell 编程核心技术《三》
- Personal thoughts on Architecture Design (this article will be revised and updated continuously later)
- Some thoughts on whether the judgment point is located in the contour
猜你喜欢

LM10丨余弦波动顺势网格策略

Lm10 cosine wave homeopathic grid strategy

Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?

MySQL数据库基本操作-DDL | 黑马程序员

BCG 使用之CBCGPProgressDlg进度条使用

OpenCV的二值化处理函数threshold()详解
关于判断点是否位于轮廓内的一点思考

Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)

【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案

在线SQL转Excel(xls/xlsx)工具
随机推荐
Personal thoughts on Architecture Design (this article will be revised and updated continuously later)
升级智能开关,“零火版”、“单火”接线方式差异有多大?
Niuke Xiaobai month race 7 F question
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
FPGA timing constraint sharing 01_ Brief description of the four steps
92. (cesium chapter) cesium building layering
牛客小白月赛7 I 新建 Microsoft Office Word 文档
HDU 6440 2018中国大学生程序设计网络选拔赛
一文掌握数仓中auto analyze的使用
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
kotlin 基本数据类型
在线SQL转Excel(xls/xlsx)工具
在线文本行固定长度填充工具
Educational codeforces round 22 E. Army Creation
Shell 编程核心技术《四》
Mysql database basic operation -ddl | dark horse programmer
HDU 1097 A hard puzzle
FPGA时序约束分享01_四大步骤简述