当前位置:网站首页>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;
}
边栏推荐
- 牛客小白月赛7 E Applese的超能力
- BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
- Functional interface
- 联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
- HDU 1372 & POJ 2243 Knight moves (breadth first search)
- "Only one trip", active recommendation and exploration of community installation and maintenance tasks
- Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
- Reflection (I)
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- 黑马程序员-软件测试--07阶段2-linux和数据库-09-24-linux命令学习步骤,通配符,绝对路径,相对路径,文件和目录常用命令,文件内容相关操作,查看日志文件,ping命令使用,
猜你喜欢
Mysql database basic operation -ddl | dark horse programmer
HMM隐马尔可夫模型最详细讲解与代码实现
Detailed explanation of the binary processing function threshold() of opencv
Stream流
Niuke Xiaobai month race 7 who is the divine Archer
牛客小白月赛7 谁是神箭手
Swagger突然发癫
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
92. (cesium chapter) cesium building layering
随机推荐
Shell 编程核心技术《二》
“只跑一趟”,小区装维任务主动推荐探索
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
Shell 编程核心技术《四》
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
BCG 使用之新建向导效果
Oracle with as ora-00903: invalid table name multi report error
92. (cesium chapter) cesium building layering
abc229 总结(区间最长连续字符 图的联通分量计数)
Several methods of online database migration
1002. A+B for Polynomials (25)(PAT甲级)
HDU 6440 2018 Chinese college student program design network competition
Find the nth power of 2
YOLOv5s-ShuffleNetV2
TCP两次挥手,你见过吗?那四次握手呢?
1006 Sign In and Sign Out(25 分)(PAT甲级)
Educational codeforces round 22 E. Army Creation
线上数据库迁移的几种方法
明明的随机数
在线文本行固定长度填充工具