当前位置:网站首页>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;
}
边栏推荐
- C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
- 【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
- 使用canal配合rocketmq监听mysql的binlog日志
- 建立自己的网站(15)
- 删除字符串中出现次数最少的字符【JS,Map排序,正则】
- 物联网应用技术的就业前景和现状
- 安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
- Shell programming core technology "three"
- Nebula Importer 数据导入实践
- 牛客小白月赛7 谁是神箭手
猜你喜欢
Hough Transform 霍夫变换原理
The 300th weekly match of leetcode (20220703)
PolyFit软件介绍
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
SSRS筛选器的IN运算(即包含于)用法
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
千万不要只学 Oracle、MySQL!
Detailed explanation of the binary processing function threshold() of opencv
使用canal配合rocketmq监听mysql的binlog日志
自由小兵儿
随机推荐
1672. 最富有客户的资产总量
牛客小白月赛7 F题
自由小兵儿
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
Hough transform Hough transform principle
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
node_exporter部署
QT realizes interface sliding switching effect
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
Other InterSystems%net tools
2021 合肥市信息学竞赛小学组
2019年蜀山区第十五届青少年信息学竞赛
测试工程师如何“攻城”(下)
Cache é JSON uses JSON adapters
php伪原创api对接方法
Is Guoyuan futures a regular platform? Is it safe to open an account in Guoyuan futures?
1008 Elevator(20 分)(PAT甲级)
Technologie de base de la programmation Shell IV
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用