problem

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 a~N1~ N2 a~N2~ ... NK a~NK~, where K is the number of nonzero terms in the polynomial, Ni and a~Ni~ (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

tip

求多项式的乘积。

answer

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define Max 1000005 int N, M;
float num[Max];
pair<int ,float> n1[Max], n2[Max]; int main(){
// freopen("test.txt", "r", stdin);
memset(num, 0, sizeof(num));
memset(n1, 0, sizeof(n1));
memset(n2, 0, sizeof(n2)); cin>>N;
for(int i = 0; i < N; i++) {
cin>>n1[i].first>>n1[i].second;
}
cin>>M;
for(int i = 0; i < M; i++) {
cin>>n2[i].first>>n2[i].second;
}
int number = 0;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
int ex = n1[i].first + n2[j].first;
float co = n1[i].second * n2[j].second;
num[ex] += co;
}
}
for(int i = 0; i < Max; i++) if(num[i] != 0) number ++;
cout<<number;
for(int i = Max -1; i >= 0; i--){
if(num[i] != 0){
cout<<" "<<i<<" ";
cout<<fixed<<setprecision(1)<<num[i];
}
} return 0;
}

experience

  • 注意数组越界问题。
  • 读清楚题意,多设计一组测试用例。

1009 Product of Polynomials (25)(25 point(s))的更多相关文章

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

  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) 2016-09-09 23:02 96人阅读 评论(0) 收藏

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

  4. A1009 Product of Polynomials (25)(25 分)

    A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...

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

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

  6. PATA 1009. Product of Polynomials (25)

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

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

  8. 1002 A+B for Polynomials (25)(25 point(s))

    problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A a ...

  9. PAT甲级 1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  10. A1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

随机推荐

  1. shell作业后台执行的方法

    来思考几种场景: 1.某个脚本需要执行时间比较长,无人值守,可能执行过程中因ssh会话超时而中断? 2.某次测试一段代码,需要临时放入后台运行? 3.放入后台运行的脚本,需要在一段时间后重新调到前台? ...

  2. iOS学习笔记(2)— UIView用户事件响应

    UIView除了负责展示内容给用户外还负责响应用户事件.本章主要介绍UIView用户交互相关的属性和方法. 1.交互相关的属性 userInteractionEnabled 默认是YES ,如果设置为 ...

  3. 音频增益响度分析 ReplayGain 附完整C代码示例【转】

    转自:http://www.cnblogs.com/cpuimage/p/8846951.html 人们所熟知的图像方面的3A算法有: AF自动对焦(Automatic Focus)自动对焦即调节摄像 ...

  4. Python3 item系列

    一.前言 #在python中一切皆对象 ''' 创建了一个dict实例-->dic就是dict的实例对象 我们通过dic['k1']可以得到k1所对应的值 那么我们自定义一个类,可不可以使用对象 ...

  5. Focal Loss笔记

    论文:<Focal Loss for Dense Object Detection> Focal Loss 是何恺明设计的为了解决one-stage目标检测在训练阶段前景类和背景类极度不均 ...

  6. ADB常用命令(二)

    参考  http://adbshell.com/commands 常用命令 查看adb 版本 adb version 打印所有附加模拟器/设备的列表 adb devices 设备序列号 adb get ...

  7. Python字符串(Str)详解

    字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可 字符串的格式 b = "hello itcast. ...

  8. 利用vw+rem实现移动web适配布局

    基本概念 1.单位 Px(CSS pixels) 像素 (px) 是一种绝对单位(absolute units), 因为无论其他相关的设置怎么变化,像素指定的值是不会变化的 其实是相对于某个设备而言的 ...

  9. Ibatis.Net 各种配置说明学习(二)

    1.各个配置文件的配置说明 providers.config:指定数据库提供者,.Net版本等信息. xxxxx.xml:映射规则. SqlMap.config:大部分配置一般都在这里,如数据库连接等 ...

  10. wpf设置某容器透明,而不应用到容器的子元素的方法

    以Border打比方: <Border.Background> <SolidColorBrush Opacity="0.4" Color="Black& ...