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 ...
随机推荐
- Java并发编程(2) AbstractQueuedSynchronizer的内部结构
一 前言 虽然已经有很多前辈已经分析过AbstractQueuedSynchronizer(简称AQS,也叫队列同步器)类,但是感觉那些点始终是别人的,看一遍甚至几遍终不会印象深刻.所以还是记录下来印 ...
- oracle环境变量详解
共享存储文件系统(NFS) 通常情况下,ORACLE_SID这个环境变量全称Oracle System Identifier,,用于在一台服务器上标识不同的实例,默认情况下,实例名就是ORACLE_S ...
- iptables详细设置
1.安装iptables防火墙 怎么知道系统是否安装了iptables?执行iptables -V,如果显示如: iptables v1.3.5 说明已经安装了iptables. 如果没有安装ipta ...
- Extjs 基础篇—— Function基础
这里主要是JS的基础知识,也是深入理解Ext的基础.1.参数可变长,注意跟Java还是有一点区别的.例: 1.function getUser(name,age){ 2.alert("nam ...
- 列表CListCtrl类使用
CListCtrl是列表控件类,列表控件的每一行叫做一个item,每一列叫做一个subitem.每一行和每一列都有个ID号,可以确定唯一的单元格. 最近使用了这个控件,有心得总结如下: (Dialog ...
- SCTP客户端与服务器
/** * @brief - Send a message, using advanced SCTP features * The sctp_sendmsg() function allows you ...
- Centos之常见目录作用介绍
我们先切换到系统根目录 / 看看根目录下有哪些目录 [root@localhost ~]# cd / [root@localhost /]# ls bin dev home lib64 mn ...
- 监控SQLServer作业执行情况脚本
SELECT [sJOB].[job_id] AS [作业ID] , [sJOB].[name] AS [作业名] , CASE WHEN [sJOBH].[run_date] IS NULL OR ...
- LeetCode691. Stickers to Spell Word
We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...
- CTF常用python库PwnTools的使用学习
之前主要是使用zio库,对pwntools的了解仅限于DynELF,以为zio就可以取代pwntools.后来发现pwntools有很多的高级用法都不曾听说过,这次学习一下用法,希望可以在以后的exp ...