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. 从hadoop 要删除字符串匹配指定的任务

    我们都知道,假设 hadoop job -list 获取当前正在执行的hadoop 任务,返回的结果例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...

  2. stream 文件操作

    简单的帮助类: private static byte[] StreamToBytes(Stream fs) { byte[] bArr = new byte[fs.Length]; fs.Read( ...

  3. STM32处理器AD难度整理

    1.STM32的AD变化,任务组可以转换成两组:规则组和注射组.随机序列按随机顺序变换多种渠道构成了一组转换.例如.能够完成转换中,例如按照以下顺序:通道3.通道8.通道2.通道2.通道0.通道2.通 ...

  4. Ubuntu 14.04 64位字体美化(使用黑文泉驿)

    Ubuntu 14.04安装和升级后,,斜体字体变得很难看,昨天,我得到一个晚上,最终,管理一个线索,这里整洁. 在线调研后,.一致的观点是,,使用开源字体库文泉驿理想的黑色字体效果,效果甚至没有丢失 ...

  5. StepShot4.3.0安装包_KeyGen发布

    StepShot是一个可以方便快速的制作操作手册的软件,功能相当强悍. 请低调使用. -------------------------------华丽的分割线-------------------- ...

  6. Telnet协议详解(远程登陆协议)

    1. 概述 Telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议.Telnet协议的目的是提供一个相对通用的,双向的,面向八位字节的通信方法,允许界面终端设备和面向终 ...

  7. Activity跳转通过EventBus传值问题

    根据阿里发布的Android开发规范:下载地址:https://102.alibaba.com/downloadFile.do?file=1520478361732/Android_v9.pdf Ac ...

  8. 深度学习概述教程--Deep Learning Overview

          引言         深度学习,即Deep Learning,是一种学习算法(Learning algorithm),亦是人工智能领域的一个重要分支.从快速发展到实际应用,短短几年时间里, ...

  9. p批处理替换目录下文本中的字符串

    @echo off rem 进入批处理文件所在的路径 cd C:\Users\zxh\Desktop\ " as "abc" ***** rem 定义要替换的新旧字符串 ...

  10. LINQ查询表达式---------from子句

    LINQ查询表达式---------from子句 LINQ的查询由3基本部分组成:获取数据源,创建查询,执行查询. //1.获取数据源 List<, , , , , }; //创建查询 var ...