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. 【CodeForces】700 D. Huffman Coding on Segment 哈夫曼树+莫队+分块

    [题目]D. Huffman Coding on Segment [题意]给定n个数字,m次询问区间[l,r]的数字的哈夫曼编码总长.1<=n,m,ai<=10^5. [算法]哈夫曼树+莫 ...

  2. Python练习-一辆购物车的寂寞都是Alex的错

    Alex大神的购物车需求: 商品列表,选择商品后加入购物车,扣款显示余额,如余额不足则提示购买此商品还需充值的金额,退出后自动结账显示余额; # 编辑者:闫龙 #弱鸡购物车程序,需求:定义金额,选择商 ...

  3. [转]GCC常用参数详解

    简介gcc and g++现在是gnu中最主要和最流行的c & c++编译器 .gcc/g++在执行编译工作的时候,总共需要以下几步:1.预处理,生成.i的文件[预处理器cpp]2.将预处理后 ...

  4. css的盒模型手机端兼容写法应该是啥样的呢?

    前言:刚刚接触css3的盒模型,感觉对于解决水平垂直居中.固定宽度/高度和可变宽度/高度同时存在这样的问题很有效.但是最近在看一个腾讯手机端框架(Frozen UI )的时候发现一个很神奇的多行文字截 ...

  5. JavaScript进阶--慕课网学习笔记

                         JAVASCRIPT—进阶篇 给变量取个名字(变量命名) 变量名字可以任意取,只不过取名字要遵循一些规则: 1.必须以字母.下划线或美元符号开头,后面可以跟字 ...

  6. IOS使用命令行打包

    1.安装证书 develop:调试证书,包含调试信息 安装时需要证书已加入设备UDID或是越狱设备才能安装. distribution:正式证书,发布到appstore所用,屏蔽了调试信息,要想测试安 ...

  7. 程序设计分层思想和DAO设计模式的开发

    无论是一个应用程序项目还是一个Web项目,我们都可以按照分层思想进行程序设计.对于分层,当下最流行划分方式是:表现层+控制层+业务层+数据层.其中,业务层和数据层被统称为后台业务层,而表现层和控制层属 ...

  8. vue-cli脚手架安装

    -1.安装淘宝镜像 $ alias cnpm="npm --registry=https://registry.npm.taobao.org \ --cache=$HOME/.npm/.ca ...

  9. C++之插入迭代器

    #include<iostream> #include<vector> #include<list> #include<iterator> usingn ...

  10. 20165301 2017-2018-2《Java程序设计》课程总结

    20165301 2017-2018-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1:我期待的师生关系 预备作业2:学习基础与c语言学习心得 预备作业3: Linux安装及命 ...