PATA 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
#include <cstdio>
const int maxn = 2001;
int main()
{
double coef[maxn]={0};
double ans[maxn]={0}; //原来直接用coef[]存储计算后的系数,导致出现问题,应另用一个ans保存 。
int k1,k2,i,j,ex,k3=0;
double co;
scanf("%d",&k1);
for(i = 0;i < k1; i++)
{
scanf("%d%lf",&ex,&co);
coef[ex] = co;
}
scanf("%d",&k2);
for(i = 0;i < k2; i++)
{
scanf("%d%lf",&ex,&co);
for(j = 0;j <1001;j++)
{
ans[ex+j] += co*coef[j];
}
}
for(i = 0;i < maxn; i++)
{
if(ans[i] != 0.0) k3++;
}
printf("%d",k3); for(i = maxn-1;i >= 0; i--)
{
if(ans[i]!=0.0){
printf(" %d %.1lf",i,ans[i]);
}
}
return 0;
}
PATA 1009. Product of Polynomials (25)的更多相关文章
- 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 ...
- 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 ...
- 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 (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- 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 ...
- 1009 Product of Polynomials (25)(25 point(s))
problem This time, you are supposed to find A*B where A and B are two polynomials. Input Specificati ...
- 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 ...
随机推荐
- c语言bit倒置最好的算法-离msb-lsb至lsb-msb
问题 什么是例如最好的算法,下面的转换? 0010 0000 => 0000 0100 从详细的转换MSB->LSB至LSB->MSB, 所有的Bit必须扭转,着.这并非字节顺序的交 ...
- Leetcode 171 Excel Sheet Column Number 字符串处理
本质是把26进制转化为10进制 A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 class Solution ...
- C ++ 17 技术上已经完成,C ++ 20 也在路上(有路线图)
在前不久结束的冬季 ISO C ++标准会议(Kona)上,C ++ 17 宣布在技术上已完成,仅剩下一些 ISO 相关的繁文缛节,即将提交至最终的 ISO 投票表决.该会议由 Plum Hall 和 ...
- ef core 数据类型 && 表字段名设置
HasColumnType HasColumnType是指定字段类型 [Column(TypeName = "decimal(18, 2)")] public decimal Mo ...
- WPF - 图形设计器(Diagram Designer)
原文:WPF - 图形设计器(Diagram Designer) OpenExpressApp计划中包括建模工具,计划是采用MetaEdit+模型来作为元模型,使用codeproject的<WP ...
- Call asynchronous method in constructor
using System; using System.ComponentModel; using System.Threading.Tasks; public sealed class NotifyT ...
- ASP.NET MVC 下UpdateModel可空未填写的参数为Null,为何不是空字符串
查了好久,终于收到原因: if (bindingContext.ModelMetadata.ConvertEmptyStringToNull && Object.Equals(valu ...
- C#连接oracle 数据库查询时输入中文查询不出来,用plsql就可以
查询语句为:select * from Per where khmc like '%李%',其实是字符集的问题. 解决方案:在连接字符串加一个“Unicode=True;”
- 微信小程序把玩(二十七)audio组件
原文:微信小程序把玩(二十七)audio组件 音频播放已经封装的很好!只需配合属性设置即可! (method和data配合使用) 主要属性: wxml <audio action="{ ...
- Android零基础入门第6节:配置优化SDK Manager,正式约会女神
原文:Android零基础入门第6节:配置优化SDK Manager,正式约会女神 在前几期中总结分享了Android的前世今生.Android 系统架构和应用组件那些事.带你一起来聊一聊Androi ...