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. gulp遇到错误:The following tasks did not complete: default Did you forget to signal async completion?

    运行之后会像下面一样报这个错误,因为事按着一个视频来写的,所以 原本的gulpfile.js如下 const gulp = require('gulp') gulp.task('default',() ...

  2. CCF-CSP题解 201703-4 地铁修建

    求1-n最长边最小的路径. 最短路变形.dis值向后延申的方式是:\[dis[j]=min(dis[j],max(dis[i],w(i,j))\] 显然满足dijkstra贪心的选择方式.spfa也当 ...

  3. mybatis初级映射

    一 前言 系统学习知识请认准知识追寻者(同公众号),错过作者,你有可能要走好多弯路 经过第一篇的入门文章,小白们都对mybatis的搭建流程应该都很熟悉,这篇文章主讲的是如何使用mybatis实现数据 ...

  4. JVM 学习笔记一 :JVM类加载机制

    前言: 最近在看JVM相关资料,这里记录下学习笔记,希望自己能坚持学完,打牢基础.   一.类加载过程 1,类从被加载到JVM中开始,到卸载为止,整个生命周期包括:加载.验证.准备.解析.初始化.使用 ...

  5. Redis来啦~~

    一. 先聊点别的 1. sql & nosql sql指关系型数据库,如Oracle,MySQL等,nosql泛指非关系型数据库,如MongoDB,Redis等:SQL数据存在特定结构的表中, ...

  6. Redis集群与分布式介绍以及搭建Redis-Cluster

    1 Redis集群 1.1 什么是集群 集群就是很多服务器组成的一个网络.指的是将多台服务器集中在一起,实现同一业务. 1.2 为什么要集群 一台服务器不能满足开发需要的时候,需要多台服务器来支持.这 ...

  7. Linux下修改MySQL数据库数据文件路径

    使用rpm安装方式安装完MySQL数据库后,数据文件的默认路径为/var/lib/mysql,然而根目录并不适合用于存储数据文件. 原路径:/var/lib/mysql 目标路径:/home/mysq ...

  8. 利用PyInstaller打包exe文件

    前言 平常我们通过Python写完一些小脚本之后,如果使用不频繁的话,一般会选择在DOS界面直接跑脚本,或者在IDE中运行.但当我们需要频繁使用某些脚本,或者在没有Python环境的机器上也能顺利运行 ...

  9. Zabbix理论知识

    Zabbix 什么是Zabbix? Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. Zabbix作用 Zabbix能够监视各种服务器的健康性.网络的稳定性 ...

  10. 怎么将CAD转JPG?教你两种CAD转JPG方法

    在CAD中,对于CAD图纸格式的转换那是比较常见的了,因为CAD图纸的格式是dwg格式的,在使用的时候不是那么的方便,就需要将CAD图纸转换为偏于查看的格式.那怎么将CAD转JPG呢?具体要怎么来进行 ...