PAT 1009 Product of Polynomials
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 (,) 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的更多相关文章
- 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 1009 Product of Polynomials 模拟
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) 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)(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)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
- 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 ...
- PATA 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
随机推荐
- 【.Net】结合项目谈谈多线程
提到多线程, 大家都知道, 在进程中启用多个线程进行工作, 会提升程序的效率等等. 本篇文章旨在解释多线程的基础概念之外, 还要结合实际的项目来谈多线程的具体使用. Thread 我们知道启动一个线程 ...
- JVM介绍
1. 什么是JVM? JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来 ...
- C#窗口禁止移动的方法
1,窗口属性中有locked属性,设置为true. (在自己进行编码的时候并没能找到这个属性,貌似只能在窗口设计时进行设置,故此方法无可控性) 2,窗口属性中有FormBorderStyle属性,设置 ...
- MongoDB数据库的基本操作
非关系型数据库(json数据库) npm install mongoose --save 启动数据酷: mongod --config /usr/local/etc/mongod.conf 这里可以将 ...
- mysql利用navicat导出表结构和表中数据
LZ在网上搜索了要如何导出mysql的表结构和表中数据,发现有的方法不好用 记录一下好用的方式: 用navicat打开DB链接后,点击数据库,右击选择转储SQL文件,然后选择结构和数据: 之后弹出新的 ...
- AFM(3)---Maude使用说明
load file-name 1可用绝对路径 2.可进入maude文件所在目录下load 3.默认工作空间是什么?
- bufferedReader中的数据, 只是读过一次, 就没有了(拿走,自然就没了),只能读一次( load, readLine 等只要是读操作)
- 《剑指offer》第六十三题(股票的最大利润)
// 面试题63:股票的最大利润 // 题目:假设把某股票的价格按照时间先后顺序存储在数组中,请问买卖交易该股 // 票可能获得的利润是多少?例如一只股票在某些时间节点的价格为{9, 11, 8, 5 ...
- es6 Set 结合 Array.from 用法
var arr=[1,2,3,2,3,4,5]; var set=new Set(arr) var arr1=Array.from(set) 重复数组 - Set 化 (去重) - 转回数组 上述 ...
- HDU 3949 XOR
3949 思路: 线性基,线性基的每个元素尽可能小 将k转换成二进制与排好序的线性基相对应 如果线性基的个数小于n,说明n个元素线性相关,所以可以构成0,k要减1 代码: #pragma GCC op ...