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. 你不知道的JavaScript(上)this和对象原型(三)

    第四章  混核对象“类” 1.理论 面向对象编程强调的是数据和操作数据的行为本质上是互相关联的.实例化,继承,多态性 javascript中只有对象,并不存在可以被实例化的“类”.一个对象并不会被复制 ...

  2. 用正则表达式【regexp】进行高级搜索数据

    正则表达式介绍 正则表达式是用来匹配文本的特殊字符集合,如果你想从一个文本中提取电话号码而已使用正则表达式,如果你需要查找名字中包含数字的所有文件可以使用正则,如果你你要在文本块中找到所有重复的单词, ...

  3. 【Java必修课】好用的Arrays.asList也有这三个坑

    好用的asList 在开发或写测试用例的过程中,经常会用到Arrays.asList()这个方法,可以快速方便地将数组转化成一个List.例如: List<String> list = A ...

  4. Windows Terminal 美化分享

    美化前:  美化后: Json分享: { "acrylicOpacity": 0.75, "closeOnExit": true, "colorSch ...

  5. Python—脚本程序生成exe可执行程序(pyinstaller)

    一.pyinstaller的简介 Python是一个脚本语言,被解释器解释执行.它的发布方式: .py文件:对于开源项目或者源码没那么重要的,直接提供源码,需要使用者自行安装Python并且安装依赖的 ...

  6. IDEA中使用Maven模板创建Maven WebApp项目并使用Tomact来运行项目

    首先需要正确安装Maven和Tomact,Maven安装和Tomact安装步骤,参见别的文章. 一.创建Maven工作空间 点击Finish按钮后,耐心等待.直到出现BUILD SUCCESS为止. ...

  7. CSS入门(背景各种属性的详解、垂直居中和过渡效果的详解、渐变效果的简单讲解、雪碧图和精灵图)

    一.各种背景属性 1.background-image 属性为元素设置背景图像. 元素的背景占据了元素的全部尺寸,包括内边距和边框,但不包括外边距. 默认地,背景图像位于元素的左上角,并在水平和垂直方 ...

  8. 1.Android-入门之系统架构介绍

    1.Android 系统架构 android分为四个层,从高层到低层分别是应用程序层.应用程序框架层.系统运行库层和linux核心层,如下图所示: 2.application应用程序层 该层提供一些核 ...

  9. VS激活(Visual Studio)

    以下是Visual Studio各个版本的激活密匙: Visual Studio Enterprise 企业版: BF8Y8-GN2QH-T84XB-QVY3B-RC4DF Visual Studio ...

  10. Python学习:50 行 Python 代码,带你追到最心爱的人

    程序员世纪难题 人们一提到程序员第一反应就是:我知道!他们工资很高啊!但大部分都是单身狗,不懂得幽默风趣,只是每天穿格子 polo 衫的宅男一个.甚至程序员自己也这样形容自己:钱多话少死的早.程序员总 ...