当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

用实际例子详细探究OpenCV的轮廓绘制函数drawContours()

PolyFit软件介绍

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

English语法_名词 - 使用

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

92.(cesium篇)cesium楼栋分层

Online sql to excel (xls/xlsx) tool

The 300th weekly match of leetcode (20220703)

Lm10 cosine wave homeopathic grid strategy

Master the use of auto analyze in data warehouse
随机推荐
1008 Elevator(20 分)(PAT甲级)
ftp、sftp文件传输
Hough Transform 霍夫变换原理
kotlin 循环控制
Niuke Xiaobai month race 7 e applese's super ability
黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
BCG 使用之CBCGPProgressDlgCtrl進度條使用
Functional interface
JVM系列之对象的创建
偏移量函数及开窗函数
Shell programming core technology "three"
HDU 1097 A hard puzzle
Educational Codeforces Round 22 E. Army Creation
Shell 编程核心技术《四》
Stream流
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
1008 elevator (20 points) (PAT class a)
The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
HDU 6440 2018中国大学生程序设计网络选拔赛