当前位置:网站首页>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;
}
边栏推荐
- 1005 Spell It Right(20 分)(PAT甲级)
- Educational codeforces round 22 E. Army Creation
- BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
- FTP, SFTP file transfer
- 长城证券开户安全吗 买股票怎么开户
- 1007 maximum subsequence sum (25 points) (PAT class a)
- The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
- The kth largest element in the array
- 爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
- The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
猜你喜欢
English grammar_ Noun - use
Online sql to excel (xls/xlsx) tool
BCG 使用之新建向导效果
OpenCV的二值化处理函数threshold()详解
FPGA timing constraint sharing 01_ Brief description of the four steps
如何使用Async-Awati异步任务处理代替BackgroundWorker?
Oracle with as ORA-00903: invalid table name 多表报错
一文掌握数仓中auto analyze的使用
西门子HMI下载时提示缺少面板映像解决方案
Stream stream
随机推荐
The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
牛客小白月赛7 F题
kotlin 类和对象
黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
Jetpack Compose 教程
1002. A+b for Polynomials (25) (PAT class a)
YOLOv5s-ShuffleNetV2
欧拉函数
Reflection (I)
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
abc229 总结(区间最长连续字符 图的联通分量计数)
Shell programming core technology "four"
1011 World Cup betting (20 points) (pat a)
An example of multi module collaboration based on NCF
1007 maximum subsequence sum (25 points) (PAT class a)
BCG 使用之CBCGPProgressDlg进度条使用
kotlin 基本数据类型
1008 Elevator(20 分)(PAT甲级)
Hough Transform 霍夫变换原理