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类型和对象

    关键字:Python 类型 对象原文:http://wiki.woodpecker.org.cn/moin/PyTypesAndObjects 关于本书 解释新式的Python对象(new-style ...

  2. 在WPF设计工具Blend2中制作立方体图片效果

    原文:在WPF设计工具Blend2中制作立方体图片效果 ------------------------------------------------------------------------ ...

  3. Python3获取股票行情数据(中国个股/中国指数/全球指数)

    #!/usr/local/bin/python3 #coding=utf-8 #source http://www.cnblogs.com/txw1958/ import os, io, sys, r ...

  4. EBS OAF 发展 URL商标、加密和编码

    EBS OAF 发展 URL商标.加密和编码 (版权声明.我原来的或翻译的文章,如需转载,转载的个人学习,转载请注明出处:否则,请与我联系.版权所有) 马克 当您指定页面定义声明URL参数,文本也能够 ...

  5. js中的escape的用法汇总

    js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1 ...

  6. OpenGL(十一) BMP真彩文件的显示和复制操作

    glut窗口除了可以绘制矢量图之外,还可以显示BMP文件,用函数glDrawPixels把内存块中的图像数据绘制到窗口上,glDrawPixels函数原型: glDrawPixels (GLsizei ...

  7. DOS符号转义(转 http://www.robvanderwoude.com/escapechars.php)

    Escape Characters Character to be escaped Escape Sequence Remark % %% May not always be required in ...

  8. [Android] 环境优化配置Android Studio发展NDK

    ======================================================== 作者:qiujuer 博客:blog.csdn.net/qiujuer 站点:www. ...

  9. 源码编译路径错误导致的Apache 无法重启问题解决方法

    问题现象: 第一次源码编译安装Apache设置路径错误,安装到/usr/local/src/ 目录下了. 删掉该目录下的安装文件,重新编译安装到/usr/local/目录下 重启apache服务时报这 ...

  10. 绕过010Editor网络验证(用python做一个仿真http server真容易,就几行代码)

    010Editor是一款非常强大的十六进制编辑器,尤其是它的模板功能在分析文件格式时相当好用!网上现在也有不少010Editor的破解版,如果没钱或者舍不得花钱买授权的话,去官方下载安装包再使用注册机 ...