[PAT甲级]1009. Product of Polynomials (25)(求多项式的积)

PAT甲级1009 测试点0 PAT甲级 测试点坑点总结1009 Product of Polynomials 1009 Product of Polynomials 测试点0:系数项可能为负数,所以有些项的系数会为零,此时不应输出 #include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; map<i... 阅读详情

1009. Product of Polynomials (25)

原题链接
相似题目 1002. A+B for 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 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

题目大意:

  • 给定两个多项式,输出它们的积
  • 样例中多项式A有2个项: 2.4 * X^1 + 3.2 * X^0
  • 样例中多项式B有2个项: 1.5 * X^2 + 0.5 * X^1
  • A*B有3个项 = 3.6 * X^3 + 6.0 * X^2+ 1.6 * X^1
  • X^2 表示 X的平方,最好是自己手写计算一下,指数相加,系数相乘
  • 精确到小数点后一位

代码:

#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int main()
{
    vector<double> v(2001);//存储最终系数,指数最大为1000,A*B最大指数是2000
    int m;
    cin >> m;
    vector<int> NK;//指数
    vector<double> ank;//系数
    for(int i=0; i<m; i++){
        int a;
        double b;
        cin >> a >> b;
        NK.push_back(a);
        ank.push_back(b);
    }
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        int a;//指数
        double b;//系数
        cin >> a >> b;
        for(int j=0; j<ank.size(); j++){
            v[a+NK[j]] += b*ank[j];
        }
    }
    vector<int> res;//保存要输出的指数
    for(int i=v.size()-1; i>=0; i--){
        if(v[i] != 0)
            res.push_back(i);
    }
    cout << res.size();
    for(int i=0; i<res.size(); i++)
        printf(" %d %.1f", res[i], v[res[i]]);
    return 0;
}
告别密码本!用Windows NPS给华为/华三交换机做Radius认证,SSH登录更安全 本文详细介绍了如何利用Windows NPS实现华为/华三交换机的Radius认证,提升SSH登录安全性。通过集中化管理、精细化控制和完整审计追踪,企业可告别传统密码本,大幅提升网络设备管理效率。文章包含NPS服务部署指南、交换机配置详解及调试技巧,助力企业构建安全高效的统一认证体系。 阅读详情

相关推荐

C# 【WebService编写调用】

😹 觉得博主文章写的不错的话,希望大家三连(✌关注,✌点赞,✌评论),多多支持一下!!!

只有登上山顶,才能看到那边的风光 1175

「PAT甲级真题解析」Advanced Level 1009 Product of Polynomials

题设要求计算两个多项式的积, 同题目1002一样, 多项式求积是有固定步骤的, 所以这是一道模拟题。 多项式求积的规则为: 将两个多项式中的项两两相乘, 相乘得到的结果项指数为两个项的和, 系数为两个项的乘积。 这意味着我们只需要用一个两重循环就可以覆盖所谓的"两两相乘", 将所有求得的结果项相加就是题设要求的多项式乘积。

过美好生活,做高效程序员 3991

普冉(PUYA)单片机开发笔记 [完结篇]:使用体会

这一篇是 PY32F003 应用实验的完结篇,总结了对这颗 MCU 的使用体会。我已经把自己实验用的代码打包上传,供各位码神参考。

Tomcat0130 - 代码生涯 9609

(PTA记录)1009 Product of Polynomials (25分)

(PTA记录)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 polynom

qq_38437955的博客 335

别再乱调了!Zygo MetroPro软件滤波功能保姆级指南,从均值到鲁棒高斯样条一次讲清

本文深入解析Zygo MetroPro软件的滤波功能,从均值滤波到鲁棒高斯样条等九种算法,帮助用户根据测量对象特性选择最佳滤波组合。通过真实工业案例和参数配置指南,提升光学测量数据的准确性和效率,特别适用于硅晶圆、光学镜片等精密测量场景。

weixin_30888413的博客 159

图腾柱无桥PFC控制逻辑解析:从双闭环到电压前馈的设计演进

本文深入解析图腾柱无桥PFC控制逻辑的设计演进,从经典双闭环控制到电压前馈技术的实现。通过分析功率波动问题和动态响应慢的症结,提出引入电压前馈的解决方案,并详细探讨数字实现中的关键注意事项。文章还涵盖控制框图的构建、稳定性分析方法及实际应用中的调参技巧,为开关电源设计提供实用指导。

weixin_29268267的博客 572

[PAT甲级]1009. 多项式乘法

PAT甲级1009题AC记录,跟之前那个多项式加法难度差不多的,会那题就能做出这题

hzykirito的博客 235

Android wifi源码分析(二) Wifi关闭流程

接着上一篇,这篇说一下Wifi的关闭流程。 由上一篇可以知道,framework层提供的wifi开关接口都是**setWifiEnabled**,只是参数不同而已。*true*表示开启wifi、*false*表示关闭wifi。

奋斗的菜鸟ing 3300

(PAT甲级) 1009 Product of Polynomials(简单模拟)

注意点,MAX要开到2010!

zeng_han_cheng的博客 234

【华为OD技术面-手撕算法代码真题】- 最长公共前缀

🌟 强烈推荐:华为OD技术面试手撕算法代码真题 🌟大家好!今天我给大家推荐一份备受赞誉的华为OD技术面试手撕算法代码真题。所有题目均为华为od实际面试过程中出现的算法代码真题。

算法大师! 4885

Vue - 解决 Property or method “__v_isRef“ is not defined on the instance but referenced(浏览器控制台报错,代码没错)

vue,vue2控制台报错,vue报错Propertyormethod"__v_isRef"isnotdefinedontheinstancebutreferenced,vue代码没问题,但是报错Propertyormethod"__v_isRef"isnotdefinedontheinstancebutreferenced,vue2如何解决报错,vue怎么解决报错问题,vue2Propertyormethod"__v_isRef"isnotdefi

🏆 前端领域优质创作者 4503

PAT甲级——(1009) Product of Polynomials

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 informati...

qq_43502020的博客 215

AI编程工具到底是初学者的绊脚石还是垫脚石?

现在是AI时代,我们要做的,是学会拥抱AI、使用AI,成为AI的驾驭者,如果你因为害怕使用AI学不到东西,那么大可不必,因为AI必然是今后的趋势,相信会用AI在今后的求职面试中也会有很大的占比。另外我之前写了多篇有关AI编程开发工具Trae的使用技巧和教程,需要的话你可以关注公众号后通过菜单栏获取。另外我也把所有Trae相关的文章整合到了腾讯ima知识库,感兴趣的可以关注公众号以后回复。

cpp加油站的专栏 189

PAT练习题(甲级) 1009 Product of Polynomials (25分)(Java实现)

PAT练习题 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 informati

CoderHqf的博客 9913

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

PAT甲级1009 Product of Polynomials

写的很抽象,不应该用map的,应该直接两层for遍历This time, you are supposed to find A×B where A and B are two polynomialsEach 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​

song0789的博客 1490

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

PAT甲级 1009 Product of Polynomials

PAT甲级 1009 Product of Polynomials 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, an...

旺崽的博客 2882

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

PAT 甲级题目讲解:1009《Product of Polynomials》

本文讲解 PAT 甲级 1009《Product of Polynomials》的完整解法。核心思路是使用**数组作为指数映射表**,通过双层循环模拟两个稀疏多项式的逐项相乘与合并同类项,时间复杂度 $O(k_1 \times k_2)$。文中给出了从输入、计算到格式化输出的分步代码,并整理了常见错误(小数精度、空格控制、忘用 `+=` 累加等)与思维拓展方向。

qq_35624947的博客 1101

PAT 甲级 1009  Product of Polynomials

1009 Product of Polynomials (25 point(s)) 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 ...

漫浸天空的雨色的备忘录~ 991

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

题目链接:PAT甲级 - 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 occ...

393

PAT甲级 1009 - Product of Polynomials

PAT甲级 1009题目 Product of Polynomials解析代码 题目 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each input file contains one test c...

qq_37208650的博客 333

PAT 甲级 1009(Product of Polynomials)

PAT 甲级 1009题目要求翻译代码思路 题目要求 翻译 题目给出两个多项式,A和B,要求我们给出A×BA\times BA×B的系数和指数。 代码 #include<iostream> using namespace std; int main() { int K1,K2; cin>>K1; float coe[2020]={0.0}; ...

qq_42865772的博客 356

PAT甲级1009 Product of Polynomials (25分)

PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小的数组,注意别越界,并且还要注意,累加的时候要变成n方的时间复杂度,输出的时候为%.1f,输入的时候为double,%lf。~~ #include <iostream> #include ...

weixin_43795683的博客 277

PAT 甲级 1009 Product of Polynomials (25 分)

题目:PAT 甲级 1009 Product of Polynomials (25 分) 经验总结: 使用unordered_map来存储第一行的项。 在输入第二行多项式时,计算并用map来存储最终结果。 记:注意项得系数之和为0的情况。 C++代码: #include<bits/stdc++.h> using namespace std; int main() { uno...

努力努力再努力 231

[PAT-Advanced] A1009 Product of Polynomials (25)

文章目录A1009 Product of Polynomials (25point(s))Input Specification:Output Specification:Sample Input:Sample Output:CodeAnalysis Author: CHEN, Yue Organization: 浙江大学 Time Limit: 400 ms Memory Limit: 64 M...

Duke 291

【PAT甲级】1009 Product of Polynomials (25 分)

1009 Product of Polynomials 题目描述: 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, an...

初见还是重逢的博客 379

[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 li...

cp0328的博客 3328
上一篇: [PAT甲级]1008. Elevator (20)(求电梯运行时间)
下一篇: [PAT甲级]1010. Radix (25)(求另一个数的基数)
whl_program
博客等级 码龄11年 101粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值