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 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 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 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 分)的更多相关文章
- 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 ...
- 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 ...
- PAT 1002. A+B for Polynomials (25) 简单模拟
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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 ...
- 【PAT甲级】1002 A+B for Polynomials (25 分)
题意:给出两个多项式,计算两个多项式的和,并以指数从大到小输出多项式的指数个数,指数和系数. AAAAAccepted code: #include<bits/stdc++.h> usin ...
- 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 ...
- 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 ...
- 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 ...
- 1002 A+B for Polynomials (25分) 格式错误
算法笔记上能踩的坑都踩了. #include<iostream> using namespace std; float a[1001];//至少1000个位置 int main(){ in ...
- 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 ...
随机推荐
- dll劫持破坏360
0x01 前言 说起DLL劫持技术,相信大家都不会陌生,因为这种技术的应用比较广泛,比如木马后门的启动.破解程序的内存补丁.外挂插件的注入以及加密狗的模拟等.之所以DLL劫持技术深受黑客们的喜爱,主要 ...
- python学习-文件I/O
12.2使用os.path操作目录 # os.path_test.py import os import time print(os.path.abspath("abc.txt") ...
- python 之 pygame
学习pygame如果不了解pygame是什么的可以产考百度或者去官网去看介绍pygame急忙趁着三分的热度,整理一下关于pygame的相关内容,顺便复习一下Markdown编辑器 pygame的介绍 ...
- php下载文件,线上文件下载
1.多个文件下载 <?php /* 把知道的图片问题名字做成一个数组 */ $mp4 = ['123','456']; /* count($mp4) 类似于 js 的 $mp4.length * ...
- 百万年薪python之路 -- 递归
递归(每当有一个函数被递归调用,就应该要有一个返回值,才能正常把递归的返回值'归'回来) 一个正经的递归: 1.不断调用自己本身 2.有明确的结束条件 递归注重于"一递 一归&quo ...
- 把图片在word中显示
如下: //放入word中 #region word ThreadPool.QueueUserWorkItem(//使用线程池 (P_temp) =>//使用lambda表达式 { G_wa = ...
- C# 8 - using声明 和 异步流
这两个主题没什么关系,但是怕文章太短被移除主页. using声明 using语句块 尽管.NET Core运行时有垃圾收集器(GC)来负责内存清理工作,但是我们还是要自己确保当非托管资源不再使用的时候 ...
- js静态属性,实例属性,封装性,prototype,__proto__综合解析
原创作品,转载请注明来源,sogeisetsu,我的csdn上也有这篇文章csdn js静态属性,实例属性,封装性,prototype,__proto__综合解析 下面是我在写博客的源代码,您可以先不 ...
- 在vue中使用Ueditor
今天研究的主角是:UEditor UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点. 版本有很多 我用的是:[1.4.3.3 PHP 版本 ...
- SpringCloud配置中心集成Gitlab(十五)
一 开始配置config服务 config-server pom.xml <dependency> <groupId>org.springframework.cloud< ...