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 coeficients(系数), 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和B,求A*B的结果。

解题思路:两个多项式相乘,系数coeficients相乘,指数exponents相加,模拟一下即可。这里由于指数是连续的,系数不连续且是小数,所以可以用数组来保存多项式,指数作为数组下标,系数保存到数组中。最后按照指数递减的顺序输出所有的不为0的项即可。

decimal  

adj. 小数的;十进位的

n. 小数

Product

n. 乘积、产物

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<map>
using namespace std;
int main()
{
int n1,n2,cnt=;
int i,j,e;
double c;
double a[]={0.0},ans[]={0.0};
scanf("%d",&n1);
for(i=;i<n1;i++)
{
scanf("%d %lf",&e,&c);
a[e]=c;
}
scanf("%d",&n2);
for(i=;i<n2;i++)
{
scanf("%d %lf",&e,&c);
for(j=;j<;j++)
{
if(a[j]!=)
{
if(a[j]*c>10.0)
{
ans[j+e+]+=(a[j]*c)/10.0;//产生进位
}
else
{
ans[j+e]+=a[j]*c;//系数相乘,指数相加
}
}
}
}
for(i=;i<;i++)
{
if(ans[i]!=)
{
cnt++;
}
}
printf("%d",cnt);//所有不为0的项数数量
for(i=-;i>=;i--)
{
if(ans[i]!=)
{
printf(" %d %.1f",i,ans[i]);
}
}
return ;
}

PAT 1009 Product of Polynomials 模拟的更多相关文章

  1. PAT 1009 Product of Polynomials

    1009 Product of Polynomials (25 分)   This time, you are supposed to find A×B where A and B are two p ...

  2. PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值

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

  3. pat 甲级 1009. Product of Polynomials (25)

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

  4. PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏

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

  5. PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)

    1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...

  6. PTA (Advanced Level) 1009 Product of Polynomials

    1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...

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

  8. PATA 1009. Product of Polynomials (25)

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

  9. 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 po ...

随机推荐

  1. 我的 FPGA 学习历程(15)—— Verilog 的 always 语句综合

    在本篇里,我们讨论 Verilog 语言的综合问题,Verilog HDL (Hardware Description Language) 中文名为硬件描述语言,而不是硬件设计语言.这个名称提醒我们是 ...

  2. 求连通块的面积 - BFS、DFS实现

    本文以Leetcode中695.岛屿的最大面积题目为基础进行展开(题目

  3. IT兄弟连 HTML5教程 CSS3属性特效 圆角

    传统的圆角生成方案,必须使用多张图片作为背景图案.CSS3的出现,使得我们再也不必浪费时间去制作这些图片了,只需要border-radius属性,支持浏览器IE 9.Opera 10.5.Safari ...

  4. 痞子衡嵌入式:恩智浦i.MX RTxxx系列MCU开发那些事 - 索引

    大家好,我是痞子衡,是正经搞技术的痞子.本系列痞子衡给大家介绍的是恩智浦i.MX RTxxx系列微控制器相关知识. 恩智浦半导体于2018年10月发布的i.MX RTxxx系列开启了ML/AI MCU ...

  5. autojump 之 git本地安装

      1.克隆autojump的repo,Terminal下执行:      git clone git://github.com/joelthelion/autojump.git      然后进入c ...

  6. 松软科技web课堂:随机Math.random()

    Math.random() 返回 0(包括) 至 1(不包括) 之间的随机数: 实例 Math.random(); // 返回随机数 JavaScript 随机整数 Math.random() 与 M ...

  7. node、npm、chrome、v8、sandbox是什么?

    这些东西有些比较常用,有些仅知道个名称,但无论是熟悉还是陌生的,要比较精确地解释这些东西,是有一定的难度,可这些东西对前端开发非常重要,还是需要有明确的概念. PS:内容点到即止,不然一个东西一篇文章 ...

  8. 完全卸载Android Studio(卸载得干干净净)

    步骤其实很简单,一共三步,但是每一步都需要完成,步骤如下: 打开控制面板或腾讯软件管家等执行常规的卸载操作. 找到SDK的安装目录手动删除SDK. 进入“C:\Users\<你的用户名下> ...

  9. 《Python3 网络爬虫开发实战》开发环境配置过程中踩过的坑

    <Python3 网络爬虫开发实战>学习资料:https://www.cnblogs.com/waiwai14/p/11698175.html 如何从墙内下载Android Studio: ...

  10. 基于Redis扩展模块的布隆过滤器使用

    什么是布隆过滤器?它实际上是一个很长的二进制向量和一系列随机映射函数.把一个目标元素通过多个hash函数的计算,将多个随机计算出的结果映射到不同的二进制向量的位中,以此来间接标记一个元素是否存在于一个 ...