1009. Product of Polynomials (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. pat 甲级 1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  4. 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 ...

  5. 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 ...

  6. 【PAT】1009. Product of Polynomials (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 像职业选手样编码:地道Python

    Code Like a Pythonista: Idiomatic Python David Goodger goodger@python.org http://python.net/~goodger ...

  2. chaos —— 混沌

    混沌,一个被严重滥用的物理数学概念. 混沌(chaos)是一个动力学系统(Dynamic System)概念,指的是确定性动力学系统因对初值敏感而表现出的不可预测的.类似随机性的运动. 1. 洛伦兹吸 ...

  3. 基于高德地图的描点操作,监听地图缩放,展示合理数量的marker

    原文:基于高德地图的描点操作,监听地图缩放,展示合理数量的marker 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/lx583274568/art ...

  4. C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码

    原文:C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码 C#WPF 如何绘制几何图形? 怎么绘制坐标系?绘制sin曲线(正弦曲线)? 这离不开Path(Syst ...

  5. 【转】CefSharp 与 js 相互调用

    转自CSDN博客博主ghui,虽然博主说要经过他同意才能转,我只是做笔记用,没做他用,所以请博主理解,在此感谢博主! 一. CefSharp调用 js CefSharp.WinForms.Chromi ...

  6. fail2ban防止暴力破解

    安装fail2ban: 将fail2ban 上传到服务器,解压: [root@xuegod1 tmp]# tar -zxvf fail2ban-0.8.14.tar.gz [root@xuegod1 ...

  7. style文件的指定

    新建资源文件   写资源文件 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/prese ...

  8. WPF VisualTreeHelper的使用

    <Window x:Class="MyWpf.MainWindow"        xmlns="http://schemas.microsoft.com/winf ...

  9. 阿里云访问控制(RAM)授权子账户管理磁盘快照

    阿里云 RAM 控制台没有提供管理磁盘快照的系统策略,需要自己添加自定义授权策略. 操作步骤: 进入 RAM 控制台 -> 策略管理,点击"新建授权策略" 选中"空 ...

  10. asp .net core 读取读取Views文件夹下的js和css

    //读取Views文件夹下的js和css app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFilePro ...