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 N​1​​ a​N​1​​​​ N​2​​ a​N​2​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (,) are the exponents and coefficients, respectively. It is given that 1,0.

Output Specification:

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:

  1. 2 1 2.4 0 3.2
  2. 2 2 1.5 1 0.5

Sample Output:

  1. 3 2 1.5 1 2.9 0 3.2
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int m,n,i,temp,count=0;
  5. float a[1002],b[1002];
  6. cin>>m;
  7. for(i=0;i<m;i++){
  8. cin>>temp;
  9. cin>>a[temp];
  10. }
  11. cin>>n;
  12. for(i=0;i<n;i++){
  13. cin>>temp;
  14. cin>>b[temp];
  15. if(a[temp]==0){
  16. a[temp]=b[temp];
  17. }
  18. else{
  19. a[temp]+=b[temp];
  20. }
  21. }
  22. for(i=0;i<1001;i++){
  23. if(a[i]!=0)
  24. count++;
  25. }
  26. cout<<count;
  27. for(i=1000;i>=0;i--){
  28. if(a[i]!=0){
  29. printf(" %d %.1f",i,a[i]);
  30. }
  31. }
  32. return 0;
  33. }

  

A+B for Polynomials的更多相关文章

  1. 1002. A+B for Polynomials (25)

    题目链接:https://www.patest.cn/contests/pat-a-practise/1002 原题如下: This time, you are supposed to find A+ ...

  2. PAT (Advanced Level) Practise:1002. A+B for Polynomials

    [题目链接] This time, you are supposed to find A+B where A and B are two polynomials. Input Each input f ...

  3. \(\S1 \) Gaussian Measure and Hermite Polynomials

    Define on \(\mathbb{R}^d\) the normalized Gaussian measure\[ d \gamma(x)=\frac{1}{(2\pi)^{\frac{d}{2 ...

  4. 1002. A+B for Polynomials

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

  5. Legendre polynomials

    In mathematics, Legendre functions are solutions to Legendre's differential equation: In particular, ...

  6. PAT 解题报告 1009. Product of Polynomials (25)

    This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: Each ...

  7. 【PAT】1009. Product of Polynomials (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...

  8. PAT 1002. A+B for Polynomials (25) 简单模拟

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  9. PAT1009:Product of Polynomials

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

  10. PAT1002:A+B for Polynomials

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

随机推荐

  1. centos7安装yum安装pip

    pip是python中的一个包管理工具,可以对Python包的查找.下载.安装.卸载的作用. yum -y install epel-release yum -y install python-pip ...

  2. tensorflow API _ 5 (tensorflow.summary)

    tensorflow的可视化是使用summary和tensorboard合作完成的. 基本用法 首先明确一点,summary也是op. 输出网络结构 with tf.Session() as sess ...

  3. js实现文字上下滚动效果

    大家都知道,做html页面时,为了提升网页的用户体验,我们需要在网页中加入一些特效,比如单行区域文字上下滚动就是经常用到的特效.如下图示效果: <html> <head> &l ...

  4. Tensorflow细节-P312-PROJECTOR

    首先进行数据预处理,需要生成.tsv..jpg文件 import matplotlib.pyplot as plt import numpy as np import os from tensorfl ...

  5. lombok常用注解@Data@AllArgsConstructor@NoArgsConstructor@Builder@Accessors

    原贴:https://blog.csdn.net/ChenXvYuan_001/article/details/84961992 https://blog.csdn.net/weixin_382293 ...

  6. CSP2019自闭记

    为什么我之前没有写呢,是因为我总是考的太lj,于是就不想写了. 这次不管考没考好都要强迫自己写,因为这是第一次参加提高组+第一次参加CSP. 当然什么初赛/复赛试题/答案什么的是不会出现的. Day ...

  7. 【POJ1068】Parencodings

    题目传送门 本题知识点:模拟 这是一道恐怖的括号题.题意稍微理解以下还是可以的. 我们针对样例来理解一下 S.P.W 到底是什么意思: S:( ( ( ( ) ( ) ( ) ) ) ) P: \(P ...

  8. JavaScript中的内存溢出与内存泄漏

    内存溢出 是一种程序运行出现的错误: 当程序运行需要的内存超过了剩余的内存时, 就出抛出内存溢出的错误 var obj = {} for (var i = 0; i < 100000; i++) ...

  9. QHUOJ - 1533: 计算组合数(大数计算)

    题目描述 给定两个正整数n,m,计算组合数C(n,m).组合数计算公式为:C(n,m)=n!/((n-m)!*m!) 已知n,m <= 50. 结果很大需要使用long long存储. 输入 输 ...

  10. Fiddler常用功能总结

    使用Fildder几年来,深深的体会到了其便利性,给工作带来了极大的便利,所以把其它常用功能总结如下 一:介绍 1.免费,支持抓取http.https协议,可独立运动 2.原理:(客户通过移动端或是P ...