PAT甲级 1009. Product of Polynomials (25分)

简介: PAT甲级 1009. Product of Polynomials (25分)

1009. Product of Polynomials (25分)


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 a**N1 N2 a**N2 … N**K aNK


where K is the number of nonzero terms in the polynomial, N**i and aNi (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤N**K<⋯<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;
    cin >> N1;
    double arr[1005] = {0.0}, ans[2005] = {0.0};
    int z;
    double x;
    for (int i = 0; i < N1; i++)
    {
        cin >> z >> x;
        arr[z] = x;
    }
    cin >> N2;
    for (int i = 0; i < N2; i++)
    {
        cin >> z >> x;
        for (int j = 0; j < 1005; j++)
        {
            if (arr[j])
            {
                ans[z + j] += arr[j] * x;
            }
        }
    }
    int count = 0;
    for (int i = 2004; i >= 0; i--)
    {
        if (ans[i])
        {
            count++;
        }
    }
    cout << count;
    for (int i = 2004; i >= 0; i--)
    {
        if (ans[i])
        {
            printf(" %d %.1f", i, ans[i]);
        }
    }
    system("pause");
    return 0;
}

多项式相乘,与1002的思路一致。

目录
相关文章
|
算法 5G
【5G NR】手机身份证号IMEI与IMEISV
手机上的“IMEI”是指国际移动设备识别码(IMEI),通常称为手机序列号。它用于识别移动网络中的各个独立手机和其他移动通信设备,相当于手机身份证号,它是全球唯一的。
1465 0
【5G NR】手机身份证号IMEI与IMEISV
|
数据可视化
R语言绘图教程丨Nature论文都在用的多组比较箱线图,自动计算显著性并标注,附带误差线
R语言绘图教程丨Nature论文都在用的多组比较箱线图,自动计算显著性并标注,附带误差线
|
8月前
|
算法
蓝桥杯16天刷题计划一一Day02
这是蓝桥杯16天刷题计划的第二天内容,由作者blue于2025年3月28日整理。当天训练重点为二分法,包含多道经典题目解析与代码实现,如有序数组查找、砍树问题、木材加工等。文章针对二分法的应用场景进行了深入讲解,并通过实例演示了如何优化算法效率,适合对二分法不熟悉的初学者学习和练习。
204 5
|
存储 应用服务中间件 nginx
CKAD考试实操指南(五)---定制你的舞台:配置实践要点
在这篇 CKAD 考试实操指南文章中将为你介绍如何使用知十平台并结合开源项目 CKAD Exercises 中提供的练习题来练习 CKAD 考试中 Configuration 部分的考试内容。在这个过程中你将掌握如何通过 kubectl 命令行工具操作「ConfigMap」、「Secret」、「SecurityContext」、「ServiceAccount」、「ResourceQuota」等资源,并在实践中加深对知识的理解。
316 0
CKAD考试实操指南(五)---定制你的舞台:配置实践要点
|
缓存 图形学 C++
Unreal学习笔记2-绘制简单三角形
Unreal学习笔记2-绘制简单三角形
191 0
|
数据挖掘 索引 Python
数据分析缺失值处理(Missing Values)——删除法、填充法、插值法
数据分析缺失值处理(Missing Values)——删除法、填充法、插值法
1796 2
|
数据采集 消息中间件 并行计算
进程、线程与协程:并发执行的三种重要概念与应用
进程、线程与协程:并发执行的三种重要概念与应用
397 0
|
Android开发 数据安全/隐私保护 iOS开发
ios和安卓测试包发布网站http://fir.im的注册与常用功能
ios和安卓测试包发布网站http://fir.im的注册与常用功能
906 0
ios和安卓测试包发布网站http://fir.im的注册与常用功能
|
存储 算法 C++
链表基础知识(二、双向链表头插、尾插、头删、尾删、查找、删除、插入)
链表基础知识(二、双向链表头插、尾插、头删、尾删、查找、删除、插入)
【Hexo】butterfly主题添加备案信息
【Hexo】butterfly主题添加备案信息
【Hexo】butterfly主题添加备案信息