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 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))的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PATA 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 【译】第十二篇 SQL Server代理多服务器管理
本篇文章是SQL Server代理系列的第十二篇,详细内容请参考原文 在这一系列的上一篇,我们查看了维护计划,一个维护计划可能会创建多个作业,多个计划.你还简单地看了SSIS子系统,并查看了维护计划作 ...
- 20165320 预备作业2:技能学习心得与C语言学习
一.技能学习心得 1.你有什么技能比大多数人好? 我觉得我的篮球打得比一般的人好吧,但是也仅仅掌握了大部分基本的篮球技巧,算不上精通. 2.针对这个技能的获取你有什么成功的经验? 我觉得要打好篮球需要 ...
- jQuery Validate自定义金钱验证,是否为金额格式,保留两位小数,并支持千分制货币格式
//自定义函数实现 isMoney: function (value, element){ // return this.optional(element) || /(^[1-9]([0-9]+)?( ...
- Lucene7.1.0版本的索引创建与查询以及维护,包括新版本的一些新特性探索!
一 吐槽 lucene版本更新实在太快了,往往旧版本都还没学会,新的就出来,而且每个版本改动都特别大,尤其是4.7,6,6,7.1.......ε=(´ο`*)))唉,但不可否认,新版本确实要比旧版本 ...
- vim加密文件
一.加密文件内容 vim gt-1.sh 输入:X 注意是大写的X 输入密码 然后,保存 再次访问,需要输入密码 如果输入密码错误,内容显示为乱码 用cat或more查看文件内容,显示为乱码:用vi重 ...
- ASP.NET MVC5 支持PUT 和DELETE
Web.config <configuration> <system.webServer> <handlers> <remove name="Ext ...
- python基础--hashlib模块
hashlib模块用于加密操作,代替了md5和sha模块, 主要提供SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法. # -*- coding:utf-8 - ...
- QUnit 实践一
项目准备启用Qunit, 先来尝试一下. 不说废话,上代码: <!DOCTYPE HTML> <html> <head> <meta http-equiv=& ...
- SQLSERVER中的人民币数字转大写的函数实现
CREATE FUNCTION [dbo].[f_num_chn] (@num numeric(14,5))RETURNS varchar(100) WITH ENCRYPTIONASBEGIN-- ...
- python 常用的标准库及第三方库
标准库Python拥有一个强大的标准库.Python语言的核心只包含数字.字符串.列表.字典.文件等常见类型和函数,而由Python标准库提供了系统管理.网络通信.文本处理.数据库接口.图形系统.XM ...