当前位置:网站首页>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;
}
边栏推荐
- Several methods of online database migration
- 有关架构设计的个人思考(本文后续不断修改更新)
- HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
- Jetpack compose tutorial
- Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
- Bi skills - permission axis
- Educational codeforces round 22 E. Army Creation
- Introduction to polyfit software
- . Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
- Opencv functions and methods related to binary threshold processing are summarized for comparison and use
猜你喜欢
To sort out messy header files, I use include what you use
牛客小白月赛7 谁是神箭手
升级智能开关,“零火版”、“单火”接线方式差异有多大?
Niuke Xiaobai month race 7 who is the divine Archer
BCG 使用之CBCGPProgressDlg进度条使用
一文掌握数仓中auto analyze的使用
Introduction to polyfit software
Pointnet/Pointnet++点云数据集处理并训练
Online text line fixed length fill tool
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
随机推荐
Qt实现界面滑动切换效果
1007 maximum subsequence sum (25 points) (PAT class a)
TCP两次挥手,你见过吗?那四次握手呢?
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
如何使用Async-Awati异步任務處理代替BackgroundWorker?
FPGA timing constraint sharing 01_ Brief description of the four steps
1006 Sign In and Sign Out(25 分)(PAT甲级)
Functional interface
The 300th weekly match of leetcode (20220703)
1008 Elevator(20 分)(PAT甲级)
1006 sign in and sign out (25 points) (PAT class a)
Oracle with as ora-00903: invalid table name multi report error
牛客小白月赛7 I 新建 Microsoft Office Word 文档
BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
How test engineers "attack the city" (Part I)
Double colon function operator and namespace explanation
HDU 1097 A hard puzzle
MySQL数据库基本操作-DDL | 黑马程序员
Online text line fixed length fill tool