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​​​​ (,) are the exponents and coefficients, respectively. It is given that 1, 0.

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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxnum 100005 double a[] = {};
double b[] = {};
double c[maxnum] = {}; int main(){
int n;cin >> n;
int t;
for(int i=;i < n;i++){
int x;double y;
cin >> x >> y;
a[x] = y;
if(!i)t = x;
}
int m;cin >> m;
int start;
for(int i=;i < m;i++){
int x;double y;
cin >> x >> y;
b[x] = y;
if(!i) start = x;
} for(int i=;i < t+;i++){
for(int j=;j < start+;j++){
c[i+j] += a[i]*b[j];
}
} int cnt = ;
for(int i=;i < maxnum;i++)if(c[i])cnt++;
cout << cnt; for(int i=maxnum-;i>=;i--){
if(c[i]) printf(" %d %.1lf",i,c[i]);
} return ;
}

空间开的有点小炸,做了一下优化就好了,再一次理解错了提议,K<10,不一定就项系数<10,还好这题没出毒瘤卡边界数据,在超过1e5的地方直接放弃了。。

 

PAT 1009 Product of Polynomials的更多相关文章

  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 1009 Product of Polynomials 模拟

    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) 2016-09-09 23:02 96人阅读 评论(0) 收藏

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

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

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

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

  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. 【创建模式】--Singleton

    设计模式之Singleton(单态) 单态定义: Singleton 模式主要作用是保证在Java应用程序中,一个类Class 只有一个实例存在. 在很多操作中,比如建立目录  数据库链接都需要这样的 ...

  2. Python实现机器学习算法:AdaBoost算法

    Python程序 ''' 数据集:Mnist 训练集数量:60000(实际使用:10000) 测试集数量:10000(实际使用:1000) 层数:40 ------------------------ ...

  3. UI之ECharts

    官网 效果图展示: 特性 ECharts,一个使用 JavaScript 实现的开源可视化库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Fir ...

  4. HDU 2426 Interesting Housing Problem(二分图最佳匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2426 题意:每n个学生和m个房间,现在要为每个学生安排一个房间居住,每个学生对于一些房间有一些满意度,如果满意度 ...

  5. BZOJ 2809: [Apio2012]dispatching(左偏树)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2809 题意: 思路:最简单的想法就是枚举管理者,在其子树中从薪水低的开始选起,但是每个节点都这样处理 ...

  6. JavaScript知识点整理

    1.JavaScript的定义 JavaScript是一种专门为与网页交互而设计的脚本语言.有下列三部分组成 ①ECMAScript,提供核心语言功能 ②文档对象模型(DOM),提供访问与操作网页内容 ...

  7. C#Listview添加数据,选中最后一行,滚屏

    this.listView.Items.Add(lvi); this.listView.EnsureVisible(this.listView.Items.Count - 1); this.listV ...

  8. 深究CSS中Position的属性和特性

    一.position的概念 作为布局必不可缺少的元素之一,深究其属性以及一些注意点是非常必要的. 定义:规定元素的定位类型. position属性: 属性 描述 常用性 absolute 生成绝对定位 ...

  9. fit_transform和transform的区别

    来自:泡泡糖nana 来自:俞驰 1. fit_transform是fit和transform的组合. 2. fit(x,y)传两个参数的是有监督学习的算法,fit(x)传一个参数的是无监督学习的算法 ...

  10. SQL中的float类型的数据

    问题1.  如何在SQL中默认的使用float类型的数据 SQL中想要通过计算的方式最快的得到一个float类型的数据,只需要运算的其中一个值后面加上小数点就ok. 比如 :9/2=4 但是 :9/2 ...