当前位置:网站首页>1009 Product of Polynomials(25 分)(PAT甲级)
1009 Product of Polynomials(25 分)(PAT甲级)
2022-07-04 17:58:00 【相思明月楼】
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
多项式的乘法。
#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;
}
边栏推荐
- Wireshark网络抓包
- HDU 1097 A hard puzzle
- Shell programming core technology II
- Go microservice (II) - detailed introduction to protobuf
- 神经网络物联网平台搭建(物联网平台搭建实战教程)
- Shell 编程核心技术《二》
- FPGA timing constraint sharing 01_ Brief description of the four steps
- 1007 Maximum Subsequence Sum(25 分)(PAT甲级)
- Stream流
- Is the securities account opened by qiniu safe?
猜你喜欢

FPGA时序约束分享01_四大步骤简述

性能优化之关键渲染路径

A method of using tree LSTM reinforcement learning for connection sequence selection

PolyFit软件介绍

“只跑一趟”,小区装维任务主动推荐探索

Nebula Importer 数据导入实践

正则替换【JS,正则表达式】

神经网络物联网平台搭建(物联网平台搭建实战教程)

Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
![[uniapp] uniapp development app online Preview PDF file](/img/11/d640338c626249057f7ad616b55c4f.png)
[uniapp] uniapp development app online Preview PDF file
随机推荐
大佬们,求助一下,我用mysql cdc 2.2.1(flink 1.14.5)写入kafka,设置
测试工程师如何“攻城”(上)
An example of multi module collaboration based on NCF
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
26. 删除有序数组中的重复项 C#解答
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
关于判断点是否位于轮廓内的一点思考
redis分布式锁的8大坑总结梳理
prometheus安装
问下各位大佬有用过cdc直接mysql to clickhouse的么
Introduction to polyfit software
Is Guoyuan futures a regular platform? Is it safe to open an account in Guoyuan futures?
Technologie de base de la programmation Shell IV
Detailed explanation of the binary processing function threshold() of opencv
Nebula importer data import practice
Don't just learn Oracle and MySQL!
Stream流
One question per day (2022-07-02) - Minimum refueling times
1672. 最富有客户的资产总量
1008 Elevator(20 分)(PAT甲级)