【PAT】1009. Product of Polynomials (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009
分析:简单题。相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序。注意点:多项式相乘后指数最高可达2000。
题目描述:
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
参考代码:
#include<iostream>
#include<iomanip>
#include<string.h>
using namespace std;#define max 1000
double input1[max + 1];
double input2[max + 1];
double result[2*max + 1];int main()
{memset(input1,0,sizeof(input1));memset(input2,0,sizeof(input2));memset(result,0,sizeof(result));int k;int i,j;int e;//int temp=0; //记录最高指数double c;int count = 0; //最终输出的多项式的项数。cin>>k;for(i=0; i<k; i++){cin>>e>>c;input1[e] += c;}cin>>k;for(i=0; i<k; i++){cin>>e>>c;input2[e] += c;}for(i=0; i<=1000; i++){for(j=0; j<=1000; j++){result[i+j] += input1[i]*input2[j];}}for(i=0; i<=2000; i++) if(result[i] != 0) count++;cout<<count;for(i=2000; i >= 0; i--){if(result[i] != 0.0) {cout<<" "<<i;cout<<fixed<<setprecision(1);cout<<" "<<result[i];}}cout<<endl;return 0;
}
转载于:https://www.cnblogs.com/pangblog/p/3279789.html
【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 分) C++ 全部AC
题目 思路 维护三个数组: arrA[1001]存储第一行数据 arrB[1001]存储第二行数据 c[1000000]存储计算结果 数组下标表示多项式的指数,数组存的内容表示多项式的系数 将arrA ...
- 【测试点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 分)
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:第一个式子 ...
- 1009 Product of Polynomials (25 分)【难度: 简单 / 知识点: 模拟】
https://pintia.cn/problem-sets/994805342720868352/problems/994805509540921344 注意:系数数据范围虽然是0-1000 但是乘 ...
- PAT(Advanced) 1009 Product of Polynomials(25 分)
2018.9.6 // 注意:一定要计算map中非0的个数,而不能用map.size();#include <iostream> #include <cstdio> #incl ...
- 1009 Product of Polynomials (25)(25 分)
题目 原题大意:求两个多项式的数乘 关键单词对照翻译如下: exponent 指数 coefficient 系数 polynomial 多项式 product 数乘 思路 最直接最快速的方法就是使用m ...
- 【PAT】B1070 结绳(25 分)
此题太给其他25分的题丢人了,只值15分 注意要求最终结果最长,而且向下取整 #include<stdio.h> #include<algorithm> using names ...
最新文章
- vue避免重新渲染_小白也能懂的VUE的生命周期探寻
- 贝叶斯分类器用于文本分类: Multinomial Naïve Bayes
- ORA-01747: user.table.column, table.column 或列说明无效
- java日期处理SimpleDateFormat等
- 关于Mac系统中 vs code下使用markdown PDF 安装Chromium失败的解决办法
- ENVI5.4中Himawari-8数据处理(向日葵8号卫星H-8)
- 最适合程序员的画图工具?
- 如何轻松集成VARCHART XGantt
- Qt输出PDF排版的技巧
- 软件测试的测试方法有哪些?
- Unity 资源断舍离(资源清理重复以及引用被引用查找)
- 问题 A: 【动态规划】机器人军团(最大不下降子序列)
- php ansiix99mac,华擎推出X99E-ITX/ac主板,终于可以把Haswell-E装进小钢炮
- Faceboxes pytorch代码解读(一) box_utils.py(上篇)
- 解决软件提示错误0xc000007b
- 阮一峰访谈问题有奖征集
- Navicat Premium和Navicat for MySQL的区别
- android 展示虚拟键盘,在android TabLayout中显示虚拟键盘
- 自用vscode安装及配置
- access的否定形式_英语 / 雅思写作中,除了not,你还会哪些否定表达?
热门文章
- 负数显示红字html语言,需要将单元格内的负数显示为红色且不带负号显示两位小数的格式代码是下面哪一种A、 0.00;[红色...
- 绝了!华为、H3C、锐捷交换机配置命令大全
- 首个沉浸式云原生 Serverless 技术实践营开启报名
- Serverless 工程实践 | Serverless 应用开发观念的转变
- 如何提升微服务的幸福感?
- 2012秋江苏省计算机二级上机试题,江苏省高校计算机等级考试二级2012秋资料.doc...
- php实现sql server数据导入到mysql数据库_php实现SQL Server数据导入Mysql数据库(示例)...
- 输入参数_MyBatis中的输入/输出参数
- 5界面怎么做窗帘拉动的效果_布艺窗帘款式有哪些?附2020年最新窗帘款式图!...
- 计算机教学实验操作环境,一种基于虚拟机的个性化计算机实验教学环境.pdf