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. 【Redis】Could not get a resource from the pool 实乃集群配置问题

    先说些题外话~自上次确诊为鼻窦炎+过敏性鼻炎到现在已经一个月了,最初那会,从下午到晚上头疼难忍.大概是积劳成疾,以前流鼻涕.打喷嚏的时候从来没有注意过,结果病根一下爆发. 关键在于锁定问题,开始治疗一 ...

  2. 数据结构1_java---单链表的操作,约瑟夫问题

    我们经常实用c++来建立链表,为了学习的方便,此处我使用java实现了对链表的增删改查功能 整个过程较为简单.仅供参考 流程: (1)通过内部类Node建立结点,内部变量作为指针域和数据域,并写下构造 ...

  3. 【阿里云IoT+YF3300】7.物联网设备表达式运算

    很多时候从设备采集的数据并不能直接使用,还需要进行处理一下.如果采用脚本处理,有点太复杂了,而采用表达式运算,则很方便地解决了此类问题. 一.  设备连接 运行环境搭建:Win7系统请下载相关的设备驱 ...

  4. Leetcode(6)Z字形变换

    Leetcode(6)Z字形变换 [题目表述]: 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" ...

  5. python-Debug、函数装饰器

    Debug操作: 程序出问题的时候可以用debug来看一下代码运行轨迹,然后找找问题在哪里 1.先给即将debug的代码打上断点:  2.打完断点之后右键点击debug:  3.然后依次点击开始按钮让 ...

  6. ESP8266 打造一款物联网产品---搭建环境编译及烧录

    一 前记 作为一个在wifi领域耕耘了多年的人,以前一直在外企和大公司做芯片,没有怎么使用过国内的芯片公司做出来的芯片.最近正好有一个项目需要用到一款低成本的wifi芯片,找来找去,发现乐鑫的最适合. ...

  7. 用Python编写简单的发红包程序和计算器原理

    用Python编写简单的发红包程序: 第一种解法:数轴方法解决 import random def red_packet(money,num): money = money * 100 #将钱数转换成 ...

  8. vue页面首次加载缓慢原因及解决方案

    第一次打包vue的项目部署到服务器下时,发现初次加载特别的缓慢,将近20s页面才加载出来,完全没有开发环境上的那么流畅.主要原因是页面在打包后如果不进行相关配置会导致资源文件特别的大,一次想要全部加载 ...

  9. MUI 混合开发移动app应用开发 --- app版本升级

    当我们的app开发完成之后,无可避免的以后会进行产品升级,那么我们希望在客户的手机上让app进行自动升级,可以分为自动升级和手动升级. 自动升级:一般在客户app第一次打开首页的时候. 手动升级:在a ...

  10. post方式实现导出/下载文件

    项目需求: 前端需要传入过多的参数给后端,get地址栏不行,只能接受post方式去导出数据 1.get的下载方式 通常下载方式如下: let url = xxxx.action?a=xx&b= ...