当前位置:网站首页>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;
}
边栏推荐
- 2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
- PolyFit软件介绍
- LeetCode第300场周赛(20220703)
- PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
- YOLOv5s-ShuffleNetV2
- 2019年蜀山区第十五届青少年信息学竞赛
- Hough Transform 霍夫变换原理
- 神经网络物联网平台搭建(物联网平台搭建实战教程)
- Pytorch学习(四)
- The 15th youth informatics competition in Shushan District in 2019
猜你喜欢

To sort out messy header files, I use include what you use

Build your own website (15)

MySQL数据库基本操作-DDL | 黑马程序员

Go微服务(二)——Protobuf详细入门

Nebula importer data import practice

神经网络物联网应用技术就业前景【欢迎补充】
关于判断点是否位于轮廓内的一点思考

There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks

FPGA timing constraint sharing 01_ Brief description of the four steps

如何使用Async-Awati异步任務處理代替BackgroundWorker?
随机推荐
Unity编辑器扩展C#遍历文件夹以及子目录下的所有图片
Other InterSystems%net tools
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
php伪原创api对接方法
Shell 编程核心技术《三》
2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
ftp、sftp文件传输
关于判断点是否位于轮廓内的一点思考
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
牛客小白月赛7 F题
Leetcode ransom letter C # answer
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
自由小兵儿
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
Introduction to polyfit software
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
Unity editor extends C to traverse all pictures in folders and subdirectories
Nebula Importer 数据导入实践
LeetCode FizzBuzz C#解答