【PAT - 甲级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
题目大意:
按照输入的格式 给定两个多项式A和B,让你按照相同的格式输出两个多项式的乘积,也就是A×B。
解题报告:
就是个模拟题,但是注意细节不少。
1.首先观察输入可以发现当系数为0的时候这一项是需要省略的。
2.其次最后输出的第一个数不是最高次项,而是后面需要跟着的数的个数。
3.次数需要从高往低输出。
4.注意进行多项式乘积的时候,跟输入的两个K是没有关系的,而是跟两组N1...Nk是有关系的,又因为这里保证了N是由大到小的,也就是只和两个N1是有关系的。
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
double A[MAX],B[MAX],C[MAX],b;
int n,m,mx,a;
int main()
{cin>>n;for(int i = 1; i<=n; i++) {scanf("%d%lf",&a,&b);A[a] = b;if(i == 1) mx = a;}cin>>m;for(int i = 1; i<=m; i++) {scanf("%d%lf",&a,&b);B[a] = b;if(i == 1) mx += a;}for(int i = 0; i<=mx; i++) {for(int j = 0; j<=mx; j++) {C[i+j] += A[i]*B[j];}}int ans = 0;for(int i = 0; i<=mx; i++) {if(C[i] != 0) ans++;}printf("%d",ans);for(int i = mx; i>=0; i--) {if(C[i] == 0) continue;printf(" %d %.1f",i,C[i]);}return 0 ;
}
【PAT - 甲级1009】Product of Polynomials (25分)(模拟,细节)相关推荐
- PAT甲级1009 Product of Polynomials (25分)
PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...
- PAT甲级 -- 1009 Product of Polynomials (25 分)
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- PAT甲级1009 Product of Polynomials:[C++题解]多项式乘法、高精度乘法
文章目录 题目分析 题目链接 题目分析 多项用一个数组来表示,数组下标表示多项式的次幂,存的内容表示多项式的系数. 然后用两重循环来计算多项式的乘法: for i : 第二个式子for j:第一个式子 ...
- 【测试点0分析】1009 Product of Polynomials (25 分)
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 This time, you are supposed to find A×B where A and B are two pol ...
- 【PAT甲级 多项式相乘】1009 Product of Polynomials (25 分) C++ 全部AC
题目 思路 维护三个数组: arrA[1001]存储第一行数据 arrB[1001]存储第二行数据 c[1000000]存储计算结果 数组下标表示多项式的指数,数组存的内容表示多项式的系数 将arrA ...
- 【PAT】1009. Product of Polynomials (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- 1009 Product of Polynomials (25 分)【难度: 简单 / 知识点: 模拟】
https://pintia.cn/problem-sets/994805342720868352/problems/994805509540921344 注意:系数数据范围虽然是0-1000 但是乘 ...
- 17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼
题目 After each PAT, the PAT Center will announce the ranking of institutions based on their students' ...
- PAT甲级-1021 Deepest Root(25分)
题目:1021 Deepest Root(25分) 分析:找出以某个节点为根时,最深的根,这题可能会超时要用vector来表示二维数组 疑问:代码一是第二次写的超时了,代码二是第一次写的AC了,找不出 ...
- PAT甲级--1007 Maximum Subsequence Sum (25 分)
题目详情 - 1007 Maximum Subsequence Sum (25 分) (pintia.cn) Given a sequence of K integers { N1, N2, .. ...
最新文章
- jieba之segment
- vbscript调用WMI一键式式发布网站
- .NET的一点历史故事:招兵买马和聚义山林
- grad在python什么模块_深度学习(Deep Learning)基础概念1:神经网络基础介绍及一层神经网络的python实现...
- 控制台下星号密码输入的实现
- Mac入门(三)使用brew安装软件
- python——reportlab
- SAP 客户端不能访问解决方案
- qemu-system-aarch64使用记录
- 未能将文件 *** \bin\Release\**.dll 复制到 \obj\Release\Package\PackageTmp\bin\***.dll VS发布程序报错 解决办法
- HTML学习笔记(二)--基础
- VSCode下载及各种实用插件安装教程
- ES (ElasticSearch) 简易解读(一)为什么用它
- 计算机图形学(曲线造型)
- 在树莓派上面 玩 仙剑奇侠传
- 国防科技大学计算机专业录取条件,国防科技大学录取条件
- 京东app优惠券python抓取_京东app商品信息爬取
- 仿QQ空间,百思不得姐下拉刷新图片放大
- 卡西欧计算机显示科学计数法怎么调回来,卡西欧计算器中的科学计数法键如何使用?请举例!急!...
- 企业实施CMMI中 常见的4大问题
热门文章
- [Bugku][Web][CTF] 9-15 write up
- oracle t44,SecureFiles LOBs基础知识之存储篇
- 653B. Bear and Compressing
- 1360E. Polygon
- Java设计模式笔记(8)装饰模式
- php获取悉尼时间,php在使用澳大利亚/悉尼时区时给出错误答案
- 浏览器获取设备信息_一条命令获取 IE 浏览器保存网站的账号和密码信息
- 六西格玛dfss_六西格玛系列知识之二:六西格玛管理的基本原理
- V210 UART TX 流程
- wince6.0编译命令分析