当前位置:网站首页>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;
}
边栏推荐
- 从实时应用角度谈通信总线仲裁机制和网络流控
- 长城证券开户安全吗 买股票怎么开户
- 与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
- Shell programming core technology II
- FPGA timing constraint sharing 01_ Brief description of the four steps
- 如何使用Async-Awati异步任务处理代替BackgroundWorker?
- 1672. 最富有客户的资产总量
- Unity editor extends C to traverse all pictures in folders and subdirectories
- LeetCode 赎金信 C#解答
- Bi skills - permission axis
猜你喜欢
神经网络物联网是什么意思通俗的解释
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
Hough transform Hough transform principle
Oracle with as ora-00903: invalid table name multi report error
Bi skills - permission axis
BI技巧丨权限轴
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
“只跑一趟”,小区装维任务主动推荐探索
每日一题(2022-07-02)——最低加油次数
在线SQL转Excel(xls/xlsx)工具
随机推荐
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
Detailed explanation of issues related to SSL certificate renewal
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
[release] a tool for testing WebService and database connection - dbtest v1.0
Stream流
整理混乱的头文件,我用include what you use
Using SSH
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
2022养生展,健康展,北京大健康展,健康产业展11月举办
PolyFit软件介绍
利用策略模式优化if代码【策略模式】
Unity editor extends C to traverse all pictures in folders and subdirectories
Hough transform Hough transform principle
How test engineers "attack the city" (Part 2)
Caché WebSocket
Online sql to excel (xls/xlsx) tool
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
Shell 编程核心技术《二》
Oracle with as ORA-00903: invalid table name 多表报错
神经网络物联网平台搭建(物联网平台搭建实战教程)