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& ...
随机推荐
- Java - Test - TestNG: testng.xml 元素 package
1. 概述 简介 package 元素 packages package exclude include 2. 背景 准备 自动生成了 testng.xml 文件 已经基本了解了 testng.xml ...
- 每天进步一点点------SOPC的Avalon-MM IP核(四) KEY_LED IP定制
/********************************************************************************* * Company : * Eng ...
- 1011 World Cup Betting
Title:1011 World Cup Betting 1. 注意点 比较简单,没有注意点 2. python3代码 def func(output): max = 0 index = -1 lin ...
- android实现扫一扫等功能
链接:https://blog.csdn.net/weixin_40399313/article/details/78814325
- 页面布局 Paddiing Row Column Expanded 组件详解
一.Paddiing 组件 padding EdgeInsetss 设置填充的值 child 组件 return Padding( padding: EdgeIn ...
- 洛谷 P5016 龙虎斗(模拟)
嗯... 题目链接:https://www.luogu.org/problem/P5016 这道题是一道模拟,不要考虑复杂,直接暴力枚举每一个点,看看加上s2之后两个势力的差值,找最小,记录下标. 注 ...
- 洛谷 P1880 [NOI1995]石子合并(区间DP)
嗯... 题目链接:https://www.luogu.org/problem/P1880 这道题特点在于石子是一个环,所以让a[i+n] = a[i](两倍长度)即可解决环的问题,然后注意求区间最小 ...
- JAVA8-用lamda表达式和增强版Comparator进行排序
1.单条件升序: list.sort(Comparator.comparing(User::getId); 2.降序: list.sort(Comparator.comparing(User::get ...
- 一个简单的C++程序及说明
一个简单的C++程序: #include<iostream> //头文件,因为输入cin,输出cout需要iostream using namespace std; //C++标准程序库中 ...
- Eclipse Tomcat 7.0 添加WEB项目报错:Tomcat version 7.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 and 6 Web modules
前言 我叫梅乾花,我误闯了“从零开始的程序世界”,遭受到了前所未有的的困难,为了活下去,为了看见美好的明天,我开始学习之旅. 问题篇我打开了"Eclipse",将项目导入其中,开启 ...