当前位置:网站首页>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;
}
边栏推荐
- Oracle with as ORA-00903: invalid table name 多表报错
- Shell programming core technology "three"
- 如何使用Async-Awati异步任务处理代替BackgroundWorker?
- 92.(cesium篇)cesium楼栋分层
- 牛客小白月赛7 E Applese的超能力
- 关于判断点是否位于轮廓内的一点思考
- Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
- Swagger突然发癫
- abc229 总结(区间最长连续字符 图的联通分量计数)
- Unity editor extends C to traverse all pictures in folders and subdirectories
猜你喜欢

Oracle with as ORA-00903: invalid table name 多表报错

Pytorch学习(四)

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

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

在线文本行固定长度填充工具

English语法_名词 - 使用

黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例

Bi skills - permission axis

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

mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
随机推荐
Educational Codeforces Round 22 E. Army Creation
Functional interface
Educational codeforces round 22 E. Army Creation
有关架构设计的个人思考(本文后续不断修改更新)
C# 使用StopWatch测量程序运行时间
Master the use of auto analyze in data warehouse
关于判断点是否位于轮廓内的一点思考
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
Leetcode ransom letter C # answer
矩阵翻转(数组模拟)
添加命名空间声明
Introduction to polyfit software
Some thoughts on whether the judgment point is located in the contour
Shell 編程核心技術《四》
26. Delete the duplicate item C solution in the ordered array
Shell programming core technology "three"
Double colon function operator and namespace explanation
基于NCF的多模块协同实例
Cbcgpprogressdlg progress bar used by BCG
HDU 6440 2018 Chinese college student program design network competition