1002 A+B for Polynomials (25 分)

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​​​​ (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10,0≤N​K​​<⋯<N​2​​<N​1​​≤1000.

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:

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 <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define wzf ((1 + sqrt(5.0)) / 2.0)
#define INF 0x3f3f3f3f
#define eps 0.0000001
#define LL long long
using namespace std; const int MAXN = 1e3 + ;
int cnt = , book[MAXN] = {}, n, a;
double A[MAXN] = {0.0}, B[MAXN] = {0.0}, C[MAXN] = {0.0}, b; int main()
{
freopen("Date1.txt", "r", stdin);
scanf("%d", &n);
while (n --)
{
scanf("%d%lf", &a, &b);
A[a] = b;
}
scanf("%d", &n);
while (n --)
{
scanf("%d%lf", &a, &b);
B[a] += b;
} for (int i = ; i >= ; -- i)
{
if (A[i] != || B[i] != )
C[i] = A[i] + B[i];
if (C[i] != )
++ cnt;
}
printf("%d", cnt);
for (int i = ; i >= ; -- i)
{
if (C[i] != )
printf(" %d %.1f", i, C[i]);
}
printf("\n");
return ;
}

pat 1002 A+B for Polynomials (25 分)的更多相关文章

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

    题目 This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: E ...

  2. PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...

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

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

  4. PAT Advanced 1002 A+B for Polynomials (25 分)(隐藏条件,多项式的系数不能为0)

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

  5. 【PAT甲级】1002 A+B for Polynomials (25 分)

    题意:给出两个多项式,计算两个多项式的和,并以指数从大到小输出多项式的指数个数,指数和系数. AAAAAccepted code: #include<bits/stdc++.h> usin ...

  6. PAT 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 con ...

  7. PAT Advanced 1009 Product of Polynomials (25 分)(vector删除元素用的是erase)

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

  8. 1002 A+B for Polynomials (25分)

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

  9. 1002 A+B for Polynomials (25分) 格式错误

    算法笔记上能踩的坑都踩了. #include<iostream> using namespace std; float a[1001];//至少1000个位置 int main(){ in ...

  10. PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值

    题目 This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: E ...

随机推荐

  1. [USACO15DEC]高低卡(白金)High Card Low Card (Platinum)

    题目描述 Bessie the cow is a hu e fan of card games, which is quite surprising, given her lack of opposa ...

  2. 在Ubuntu16.0.4安装hipcaffe

    1. 安装 AMD ROCm 显卡条件 要安装AMD的 ROCm显卡,必须满足以下条件,只能高于下面信息版本,不能低于. Distribution Kernel GCC GLIBC x86_64 Fe ...

  3. 将JSON反序列化为指定的.NET类型

    前言: 关于将JSON格式数据反序列化为指定的.NET类型数据常见的场景就是,关于网络请求获取请求成功的响应数据.本篇主要讲的的是如何通过使用Newtonsoft.Json中的JsonConvert. ...

  4. Windows 批量修改文件后缀名

    利用ren 文件名替换命令 for循环去批处理 @echo off for %%m in (*) do ( if not "%%m"=="temp.bat"( ...

  5. Mongoose-modified-at 时间自动记录插件介绍

    Mongoose-modified-at 是一款自动更新字段变化时间并记录到数据库中的 Mongoose 插件,类似 Mongoose 自带的 timestamps 功能. 使用场景 让我们考虑一个场 ...

  6. 玩转 RTC时钟库 DS3231

    1.前言     接着博主的上一篇 玩转 RTC时钟库 + DS1302,这一篇我们重点讲解DS3231时钟模块.没有看过上一篇的同学,麻烦先去阅读一下,因为很多理论基础已经在上一篇做了详细讲解,这里 ...

  7. 在idea中添加try/catch的快捷键

    在idea中添加try/catch的快捷键ctrl+alt+t选中想被try/catch包围的语句,同时按下ctrl+alt+t,出现下图

  8. 微信小程序文件压缩上传

    试用场景:上传图片过大,需进行压缩处理. 涉及微信API API 说明 文档 chooseImage 选择图片 https://developers.weixin.qq.com/miniprogram ...

  9. unity 基于scrollRect实现翻页显示

    unity 基于scrollRect实现翻页显示,并定为到某一页,而不是某一页的中间方法(第二个脚本采用实际位置计算,并在update里实现平滑过渡): 组场景时,经常需要获取鼠标(或者点击)开始结束 ...

  10. 修改linux系统history命令的条数和格式

    在一次测试环境遇到的情况,发现服务莫名其妙挂了,以为服务有bug,查了一下午,后来一个同事说,是我把服务关了啊.... 是可忍孰不可忍,原生的history命令,只能看到输入的命令历史,看不到什么时候 ...