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. luogu P3380 【模板】二逼平衡树(分块实现)

    题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 查询 \(k\) 在区间内的排名 查询区间内排名为 \(k\) 的值 修改某一位值上的数值 查询 \(k\ ...

  2. 概念理解:boost::asio::定时器2

    多线程同步回调#include <cstdio> #include <iostream> #include <boost/asio.hpp> #include &l ...

  3. jmeter-定时器使用

    在一般性能测试过程中,往往在前一个请求之后等待一段时间再执行下一个请求,这时会用到定时器. 以下列举常用的3中: 1.固定定时器: 2.

  4. leetcode 刷500道题,笔试/面试稳过吗?谈一谈这些年来算法的学习

    想要学习算法.应付笔试或者应付面试手撕算法题,相信大部分人都会去刷 Leetcode,有读者问?如果我在 leetcode 坚持刷它个 500 道题,以后笔试/面试稳吗? 这里我说下我的个人看法,我认 ...

  5. 实现Button的动态响应

    按下不同的Button实现不同的逻辑 但用同样的代码: using System.Reflection; namespace valuableBook { /// <summary> // ...

  6. Swagger -- 解决日期不正确

    继  Swagger--解决日期格式显示为Unix时间戳格式 UTC格式 这篇博客解决的日期格式后又发现了一个问题 问题 查询出来的时间没有注意到足足少了8个小时,如图 解决 其实这个问题不是Swag ...

  7. 别说家庭组开不了,一定成功的方法|win7家庭组无法开启|win7如何共享打印机

    两台WIN7要开启家庭组并且共享打印机 这两台电脑必须打开以下服务:dnscache(任务管理器 简写).fdrespub(任务管理器 简写).(接下来下了都是服务里面的)SSDP Discovery ...

  8. navicat cannot load oci dll||oracle 改字符集为GBK后 navicat 连不上||Ora-28547 ora net错误

    此段适用于 解决 navicat cannot load oci dll 环境 Navicat Premium  和 oracle 原因,navicat 32 和64 都只支持 32位的oci.dll ...

  9. 蓝桥杯基础练习 Huffuman树

    基础练习 Huffuman树 问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, -, pn-1},用这列数构造Hu ...

  10. Linux文件同步工具之rsync

    学习背景 1.最近公司的项目在使用jenkins做自动化构建,因为jenkins在构建时是比较耗性能的,便单独使用了一台服务器做构建服务器.但是个人觉得这样成本过高,单独拿一台服务器来构建并且该服务器 ...