pat1002. A+B for Polynomials (25)
1002. A+B for Polynomials (25)
This time, you are supposed to find A+B where A and B are two polynomials.
Input
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
For each test case you should output the sum 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 to 1 decimal place.
Sample Input
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output
3 2 1.5 1 2.9 0 3.2
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
double co[];
#define inf 1e-8
int main()
{
//freopen("D:\\INPUT.txt","r",stdin);
int i,k,ex;
double num;
int sumcount=;
scanf("%d",&k);
while(k--){
scanf("%d %lf",&ex,&num);
co[ex]=num;
}
scanf("%d",&k);
while(k--){
scanf("%d %lf",&ex,&num);
co[ex]+=num;
}
for(i=;i>=;i--){
if(fabs(co[i])<inf){
continue;
}
sumcount++;
}
printf("%d",sumcount);
for(i=;i>=;i--){
if(fabs(co[i])<inf){
continue;
}
printf(" %d %.1lf",i,co[i]);
}
printf("\n");
return ;
}
pat1002. A+B for Polynomials (25)的更多相关文章
- PAT 1002. A+B for Polynomials (25) 简单模拟
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT1002:A+B for Polynomials
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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 ...
- PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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 甲级 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】1002. A+B for Polynomials (25)
1002. A+B for Polynomials (25) This time, you are supposed to find A+B where A and B are two polynom ...
- 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 ...
- pat1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
随机推荐
- ubuntu安装hadoop经验
安装环境: 1 linux系统 2 或(windows下)虚拟机 本文在linux系统ubuntu下尝试安装hadoop 安装前提 1 安装JDK(安装oracle公司的JDK ) (1)检查是否已安 ...
- History命令用法15例
以下内容为转载: 如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率.本文将通过实例的方式向你介绍 history 命令的 15 个用法. 使用 HISTT ...
- Python flask虚拟环境安装
1.安装virtualenv 2.在当前路径下创建文件夹,启动虚拟环境 3.在使用虚拟环境前需激活,前面出现(env说明在虚拟环境中).虚拟环境中默认安装了pip,所以直接pip安装flask 4.在 ...
- NOIP2018初赛总结(提高组)(试题+答案+简要解析)
NOIP2018初赛总结(提高组) 更新完毕(纯手敲),如果有错误请在下面留言 单选题 T1.下列四个不同进制的数中,与其它三项数值上不相等的是 A.\((269)_{16}\) B.\((617)_ ...
- linux select代码框架
#define PORT 1234 #define BACKLOG 5 #define MAXDATASIZE 1000 typedef struct CLIENT{ int fd; char* na ...
- Eclipse 创建Maven 项目
https://www.cnblogs.com/noteless/p/5213075.html
- 【转】C#中HttpWebRequest的GetRequestStream执行的效率太低,甚至偶尔死掉
http://www.cnblogs.com/summer_adai/archive/2013/04/26/3045261.html
- 19.Longest Substring Without Repeating Characters(长度最长的不重复子串)
Level: Medium 题目描述: Given a string, find the length of the longest substring without repeating cha ...
- anglarJs前端控制器的继承
继承就是将相关内容进行抽离,将公共部分进行分离,然后被其他模块继承就可以实现多用 例如抽离分页部分: //品牌控制层 app.controller('baseController' ,function ...
- Linode安装环境
Ubuntu 18 密码:Fenghaiyan35 netstat -plnt //查看所有文件 sudo apt-get install apac ...