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 ClassLoader,到了该彻底理解它的时候了
ClassLoader 是 Java 届最为神秘的技术之一,无数人被它伤透了脑筋,摸不清门道究竟在哪里.网上的文章也是一篇又一篇,经过本人的亲自鉴定,绝大部分内容都是在误导别人.本文我带读者彻底吃透 ...
- 【Vue实例生命周期】
目录 实例创建之前执行--beforeCreate 实例创建之后执行--created 挂载之前执行--beforeMount 挂载之后执行--mounted 数据更新之前执行--beforeUpda ...
- Intellij Idea2019版本激活,目前可以激活到2089,解决失效问题(非商业用途)
目录 Intellij Idea2019版本激活,目测可以激活到2089!! 前言-此教程仅用作个人学习,请勿用于商业获利,造成后果自负!!! 步骤(直接激活新下载的) 成功 注意(不想重新下载的小伙 ...
- js加密(八)新浪微博登录
1. url: https://weibo.com/ 2. target: 登录 3. 分析.由于需要填写验证码,本篇只分析破解用户名和密码加密部分,不做验证码识别. 3.1 老规矩,F12,随便输入 ...
- 为什么要使用wsgi协议
一个cs模型是由服务器和客户端组成,大多相互情况下也就是服务器端和浏览器之间的通信.通过浏览器请求服务器,然后服务器再响应浏览器. 那么如果浏览器想要请求一个python文件,例如http://127 ...
- Jmeter 断言使用
先说一下使用断言的目的:在request的返回层面增加一层判断机制.因为request成功了,并不代表结果一定正确.类似于QTP中的检查点检查点.断言的使用方法: step_1:在你选择的Sample ...
- Kubernetes(k8s)完整安装教程
Kubernetes(k8s)完整安装教程 2019-08-27 2.3k 记录 发表评论 目录 1 安装 1.1 安装 Docker 1.2 安装 VirtualBox 1.3 安装 kubect ...
- bootstrap下拉选择框倒三角所占宽度
<select id="edit" class="form-control" style="width:42%;padding-right: 3 ...
- 吴裕雄 PYTHON 神经网络——TENSORFLOW 双隐藏层自编码器设计处理MNIST手写数字数据集并使用TENSORBORD描绘神经网络数据2
import os import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data os.envi ...
- 【PAT甲级】1096 Consecutive Factors (20 分)
题意: 输入一个int范围内的正整数,输出它最多可以被分解为多少个连续的因子并输出这些因子以*连接. trick: 测试点5包含N本身是一个素数的数据,此时应当输出1并把N输出. 测试点5包含一个2e ...