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. Laravel 虚拟开发环境 Homestead 密码

    默认数据库账号密码账号: homestead 密码:secret 默认 ssh 账号密码账号:vagrant 密码:vagrant创建默认 root 用户sudo passwd root

  2. MySQL删除语句比较,清空表数据,重置自增长索引

    drop truncate delete 程度从强到弱 1.drop table tbdrop将表格直接删除,没有办法找回 2.truncate (table) tbtruncate 删除表中的所有数 ...

  3. Redis-消息

    Redis 发布订阅(实际开发不使用) Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息. Redis 客户端可以订阅任意数量的频道. 下图 ...

  4. SpringBoot踩坑记(HTTP 400 错误)

    HTTP 400 错误 复现错误 ajax请求后台数据时有时会报 HTTP 400 错误 - 请求无效 (Bad request);出现这个请求无效报错说明请求没有进入到后台服务里:原因:1)前端提交 ...

  5. JAVA基础学习(4)之循环控制

    4循环控制 4.1 for循环 4.1.1 for循环 固定次数for循环 先执行一次do-while循环 其他while循环 Scanner in = new Scanner(System.in); ...

  6. 《实战Java高并发程序设计》读书笔记四

    第四章 锁的优化及注意事项 1.锁性能的几点建议 减小锁持有时间: 系统持有锁时间越长锁竞争程度就越激烈,只对需要同步的方法加锁,可以减小锁持有时间进而提高锁性能. 减少锁的持有时间有助于降低锁冲突的 ...

  7. mysql之mysql的安装

    此次MySQL安装的版本为:MySQL8.0 系统为:centos6.9 64位 一.利用yum仓库安装 wget https://repo.mysql.com//mysql80-community- ...

  8. SQLite - C/C++接口 API(二)

    1.打开数据库 SQLITE_API int sqlite3_open16( const void *filename, /* Database filename (UTF-16) */ sqlite ...

  9. ABC156 F - Modularness

    题目链接 题意还是比较清楚的,给你q个询问,对每组询问的模数和初始值不同,求满足条件\(a_j~\textrm{mod}~m_i < a_{j + 1}~\textrm{mod}~m_i,(0 ...

  10. 5_1 大理石在哪儿(UVa10474)<排序与查找>

    Raju和Meena喜欢玩弹珠,他们有许多上面有号码的弹珠.一开始时,Raju按照弹珠上面的号码由小到大排成一列,然后Meena会要求Raju找出某个号码的第一颗弹珠所在的位置.她会算1…2…3…,如 ...