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 polynomial:

K N​1​​ a​N​1​​​​ N​2​​ a​N​2​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤N​K​​<⋯<N​2​​<N​1​​≤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

注意系数为0的情况

#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<stack>
#include<algorithm>
#include<map>
#include<string.h>
#include<string>
#define MAX 1000000
#define ll long long
using namespace std;
double a[],b[],c[];
double y;
int x;
int main()
{
int k;
cin>>k;
for(int i=;i<;i++)
a[i]=b[i]=c[i]=;
for(int i=;i<k;i++)
{
cin>>x>>y;
a[x]=y;
}
cin>>k;
for(int i=;i<k;i++)
{
cin>>x>>y;
b[x]=y;
}
for(int i=;i<;i++)
{
for(int j=;j<;j++)
c[i+j]=c[i+j]+a[i]*b[j];//合并同类项
} int cnt=;
for(int i=;i<;i++)
{
if(c[i]!=)//去除多项式系数为0的项
cnt++;
}
cout<<cnt;
for(int i=;i>=;i--)
{
if(c[i]!=)
printf(" %d %.1lf",i,c[i] );
}
cout<<endl;
return ;
}
 

1009 Product of Polynomials (25分) 多项式乘法的更多相关文章

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

  2. PAT Advanced 1009 Product of Polynomials (25 分)(vector删除元素用的是erase)

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

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

    题意: 给出两个多项式,计算两个多项式的积,并以指数从大到小输出多项式的指数个数,指数和系数. trick: 这道题数据未知,导致测试的时候发现不了问题所在. 用set统计非零项时,通过set.siz ...

  4. 1009 Product of Polynomials (25分) 晚上脑子就是容易僵住

    #include<iostream> using namespace std; struct { int a; double b; }poly[1001]; double a[2001]; ...

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

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

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

  8. PATA 1009. Product of Polynomials (25)

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

  9. PAT甲题题解-1009. Product of Polynomials (25)-多项式相乘

    多项式相乘 注意相乘结果的多项式要开两倍的大小!!! #include <iostream> #include <cstdio> #include <algorithm& ...

随机推荐

  1. samba对外开放的端口

    前言搭建samba的时候,如果是在内网\测试环境中,可以直接关闭防火墙,但是如果是在外网情况下,需要对防火墙开放某些端口.开放的具体步骤,下面我们来看. 操作步骤1.添加端口 firewall-cmd ...

  2. Eclipse导入git上的maven web项目 以及部署成功运行

      在公司开发的时候都是用maven 以及git环境 开发的环境,那么我们初学者怎么将公司的项目成功导入到eclipse中,并且成功运行那???下面的教程就可以告诉大家~ (ps:第二步可能是大家会遇 ...

  3. GBK与Unicode的转换

    一.GBK转换到Unicode编码 std::string Gbk2Unicode(std::string &strValue) { std::string strReturn; unsign ...

  4. Anaconda"无法定位程序输入点 OPENSSL_sk_new_reserve 于动态链接库Anaconda3\Library\bin\libssl-1_1-x64.dll上"的解决办法

    Anaconda"无法定位程序输入点 OPENSSL_sk_new_reserve 于动态链接库Anaconda3\Library\bin\libssl-1_1-x64.dll上" ...

  5. MongoDB - 用户名密码认证

    参考 offical doc medium Mongo roles说明 https://docs.mongodb.com/manual/reference/built-in-roles/#userAd ...

  6. Windows上搭建hexo博客

    1.windows上下载git(官网太慢),建议去其他地方下载啊(右键出现 Git Bash Here 的标志就安装完成) 2.安装npm:http://nodejs.cn/download/ 3.安 ...

  7. websocket协议实现

    # websocket协议实现 1.抓包 wireshark规则: tcp.port == 9000 2. 结果解析 客户端请求: GET /ws/test_2 HTTP/1.1 Host: loca ...

  8. HyperLedger Fabric 资料网址大全

    BLOCKCHAIN FOR DEVELOPERS 官方网址 i. 这个网址是ibm给的测试网址,注册进去就可以设置4个节点的区块链,而且有智能合约可以测试 区块链和HyperLedger开源技术讲堂 ...

  9. 【CSS属性#2】

    " 目录 一.盒子模型 二.外边距 margin 三.内填充 padding 四.浮动 float 五.清除浮动 clear 六.溢出 overflow 七.定位 position 1. 无 ...

  10. 【前端之BOM和DOM】

    " 目录 #. window对象介绍 #. window子对象 1. 浏览器对象 navigator 2. 屏幕对象 screen 3. 历史 history 4. 地址(URL)  loc ...