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 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 coefficients, 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
注意系数为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分) 多项式乘法的更多相关文章
- 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 ...
- 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 ...
- 【PAT甲级】1009 Product of Polynomials (25 分)
题意: 给出两个多项式,计算两个多项式的积,并以指数从大到小输出多项式的指数个数,指数和系数. trick: 这道题数据未知,导致测试的时候发现不了问题所在. 用set统计非零项时,通过set.siz ...
- 1009 Product of Polynomials (25分) 晚上脑子就是容易僵住
#include<iostream> using namespace std; struct { int a; double b; }poly[1001]; double a[2001]; ...
- 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 ...
- 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 ...
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PATA 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT甲题题解-1009. Product of Polynomials (25)-多项式相乘
多项式相乘 注意相乘结果的多项式要开两倍的大小!!! #include <iostream> #include <cstdio> #include <algorithm& ...
随机推荐
- Multism中的一些特殊元器件在哪里找
1.TLP521-1(光耦)在哪里找 2.单刀双掷开关 3.数码管 indicator:指示器 SEVEN_SEG_DECIMAL_COM_A_BULE: 七段带小数点共阳极,蓝色显示 A:阳极 K: ...
- 会话技术之Cookie
在无状态的客户端(未登录)下,张三想买手机然后把手机加入购物车,服务器发出添加成功的响应,然后把手机加入ServletContext域里,然后张三想在逛逛别的, 再无状态的客户端(未登录)下,李四想买 ...
- 移动端 vue + mintUI 实现头部页签切换,按需加载~
记录~记录~~有时候,我们会遇到一个页面有两个页签切换需求,但是为了避免同时加载两个页面,我们要做到的就是当前进入的是那个页面,就先加载哪一个页面,并且也不会造成浏览器地址的变化.一开始我使用的方法是 ...
- java中路径的问题
在java中,涉及路径的问题有很多,不管在windows还是linux系统中,不要纠结”/“分隔符的使用,在windows系统中,资源加载器会自动的将”/“转换成”\“. 在java中获取资源的方式有 ...
- zookeeper 源码(二) session 和 处理事务请求
问题 session 如何生成的?sessionId为什么不直接使用时间戳+单机名 sessionid 关闭的时候的逻辑,sessionid 的维护是由各节点还是leader ? 会话相关 sessi ...
- 彻底解决Spring mvc中时间的转换和序列化等问题
痛点 在使用Spring mvc 进行开发时我们经常遇到前端传来的某种格式的时间字符串无法用java8的新特性java.time包下的具体类型参数来直接接收. 我们使用含有java.time封装类型的 ...
- buuctf——easyjava
虽然学过Javaweb的开发,但没好好学,所以对Javaweb了解不深 菜的真实 WEB-INF/web.xml泄露 贴一个别人的源码泄露总结ctf/web源码泄露及利用办法[总结中] WEB-INF ...
- 4_1 古老的密码(UVa1339)<排序>
古罗马帝国与各部门有一个强有力的政府系统,包括一个秘密服务部门.重要的文件以加密的形式发送防止窃听.在那个时代最流行的密码被称为替代密码和置换密码.例如,应用替代密码,改变所有字母“A”到“Y”字母表 ...
- DotNet中静态成员、静态类、静态构造方法和实例构造方法的区别与联系
在面向对象的C#程序设计中,关于静态的概念一直是很多人搞不明白的.下面介绍这些带“静态”的名称. 1.静态成员: 定义:静态成员是用static关键字修饰的成员(包括字段属性和方法) 所属:静态成员是 ...
- Springboot学习:日志
介绍 市面上的日志框架: JUL.JCL.Jboss-logging.logback.log4j.log4j2.slf4j.... 日志门面 (日志的抽象层) 日志实现 JCL(Jakarta Com ...