题目

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 k,m,n;int cnt=0;double a;double c[2001]={0.0},p[1001]={0.0};scanf("%d",&k);for(int i=0;i<k;i++){scanf("%d %lf",&n,&a);p[n]=a;}scanf("%d",&m);for(int i=0;i<m;i++){scanf("%d %lf",&n,&a);for(int j=0;j<1001;j++){c[j+n]+=p[j] * a;//特别想说这个的j不是指第一行的对数,是指数出现的情况数}}for(int i=0;i<2001;i++){if(c[i]!=0.0) cnt++;}printf("%d",cnt);for(int i=2000;i>=0;i--){if(c[i]!=0.0) printf(" %d %0.1f",i,c[i]);}return 0;
}

怎么说呢,我一开始不很理解交叉相乘怎么操作。其实一般都是固定一行作为外层循环,然后内层遍历另一行的所有情况。这里的所有情况不是指输入的对数,而是参数的可能性的范围。这里指数是主要考虑参数,所以循环从0到1000。

还有一点要关注的是,用double还是float的问题。其实是都可以的~

PAT甲级1009 多项式相乘相关推荐

  1. PAT甲级1009 Product of Polynomials:[C++题解]多项式乘法、高精度乘法

    文章目录 题目分析 题目链接 题目分析 多项用一个数组来表示,数组下标表示多项式的次幂,存的内容表示多项式的系数. 然后用两重循环来计算多项式的乘法: for i : 第二个式子for j:第一个式子 ...

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

    PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...

  3. PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名...

    题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...

  4. 浙大 PAT 甲级1009

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

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

  6. 【PAT - 甲级1009】Product of Polynomials (25分)(模拟,细节)

    题干: This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: ...

  7. PAT甲级1002 多项式相加

    题目 This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file ...

  8. 【PAT甲级 多项式相乘】1009 Product of Polynomials (25 分) C++ 全部AC

    题目 思路 维护三个数组: arrA[1001]存储第一行数据 arrB[1001]存储第二行数据 c[1000000]存储计算结果 数组下标表示多项式的指数,数组存的内容表示多项式的系数 将arrA ...

  9. PAT甲级1002 A+B for Polynomials:[C++题解]字符串、多项式加法或高精度加法

    文章目录 题目分析 题目链接 题目分析 本题数据范围是1000 ,可以开一个数组 X [ ] ,X[i ]表示多项式中次幂是i的系数是多少. 因此,本题可以开两个数组,对应相加,然后输出非零项即可. ...

最新文章

  1. 解决POST数据时因启用Csrf出现的400错误
  2. 软件可读性和效率取舍_网络通信设计中的一些限制和取舍:摘要
  3. Python中的find()
  4. 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
  5. spark uniq 本质上就是单词计数
  6. 《HTML5多媒体应用开发》——第2章 HTML5多媒体元素2.1 Web多媒体历史
  7. 每天一道LeetCode-----数独盘求解
  8. ubuntu samba服务器的安装文件,在Ubuntu16.04中搭建samba服务器并用win10连接实现共享文件...
  9. ant target间的dependency
  10. leetcode 127. 单词接龙(bfs)
  11. c语言告白,C语言告白代码,一闪一闪亮晶晶~
  12. vs发布项目webconfig替换语法
  13. 引入html页面比较,前端页面如何引入公用的页面header和footer
  14. swift3.0 coreData的基本使用,简单实现增删改查
  15. 挂载、卸载、free查看内存情况、创建交换分区、回环设备、dd命令、自动挂载、fuser...
  16. Flash Player离线安装包下载
  17. 运行CATIA2018主程序setup.exe时,报错setup:Problem with VC11 Runtime installation
  18. Google Chrome自定义新标签页
  19. xml 硕正报表_主要指标及功能清单
  20. Linux DNS之正向解析(邮件记录、别名解析、泛域名解析)

热门文章

  1. 森林门前的小路用计算机弹奏歌曲,抖音森林外的小路是什么歌 森林外的小路歌曲介绍...
  2. jinyuan oracle,简述Oracle IOT(Index Organized Table)(下)
  3. win7计算机记忆窗口,Win7系统关闭和打开搜索记忆功能的方法(图文教程)
  4. 计算机考试没考好的检讨书,关于考试没考好检讨书(精选5篇)
  5. linux系统入门命令大全,Linux常用命令5 - Linux 入门常用命令_Linux教程_Linux公社-Linux系统门户网站...
  6. [译][Tkinter 教程15] event 事件绑定
  7. MAC PHP Composer
  8. 大数据爆炸改变企业的决策
  9. 洛谷 P1137 旅行计划
  10. Android proguard-rules.pro 混淆模板