pat1002. 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
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
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<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
double co[];
#define inf 1e-8
int main()
{
//freopen("D:\\INPUT.txt","r",stdin);
int i,k,ex;
double num;
int sumcount=;
scanf("%d",&k);
while(k--){
scanf("%d %lf",&ex,&num);
co[ex]=num;
}
scanf("%d",&k);
while(k--){
scanf("%d %lf",&ex,&num);
co[ex]+=num;
}
for(i=;i>=;i--){
if(fabs(co[i])<inf){
continue;
}
sumcount++;
}
printf("%d",sumcount);
for(i=;i>=;i--){
if(fabs(co[i])<inf){
continue;
}
printf(" %d %.1lf",i,co[i]);
}
printf("\n");
return ;
}
pat1002. A+B for Polynomials (25)的更多相关文章
- PAT 1002. A+B for Polynomials (25) 简单模拟
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT1002:A+B for Polynomials
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 1002 A+B for Polynomials (25)(25 point(s))
problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A a ...
- PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)
1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...
- 【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 polynom ...
- PAT甲级 1002 A+B for Polynomials (25)(25 分)
1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...
- pat1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
随机推荐
- [转]Marshaling a SAFEARRAY of Managed Structures by P/Invoke Part 3.
1. Introduction. 1.1 In part 1 of this series of articles, I demonstrated how to transfer managed ar ...
- .NET 开源GIS解决方案一 概述
写在前面 最近开始研究开源GIS,国内开源GIS的资料很少,而基于.net的又是少之又少.所以决定把自己研究的资料进行总结整理,技术在于分享,本系列(计划是写一个系列,如果我可以坚持下来的话)部分是自 ...
- dedecms有缩略图则显示缩略图,没有则显示随机缩略图
随着html5以及扁平化等新的设计概念的深入人心,缩略图功能则成了一般网页模版制作不可或缺的一个功能,dedecms默认的的缩略图调用标签[field:imglink/] 或者 [field:litp ...
- P3379 【模板】最近公共祖先(LCA)(LCT)
\(\color{#0066ff}{ 题目描述 }\) 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先. \(\color{#0066ff}{输入格式}\) 第一行包含三个正整数N.M. ...
- ExtJS 4.2.1学习笔记(二)——主题theme
1 UI组件基础 学习ExtJs就是学习组件的使用.ExtJs4对框架进行了重构,其中最重要的就是形成了一个结构及层次分明的组件体系,由这些组件形成了Ext的控件. E ...
- CF796C Bank Hacking 思维
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search f ...
- 牛客寒假算法基础集训营4 I Applese 的回文串
链接:https://ac.nowcoder.com/acm/contest/330/I来源:牛客网 自从 Applese 学会了字符串之后,精通各种字符串算法,比如……判断一个字符串是不是回文串. ...
- JiJiDown
发生了预料之外的错误:System.Reflection.TargetInvocationException: Exception has been thrown by the target of a ...
- POJ2686 Traveling by Stagecoach(状压DP)
题意: 有一个旅行家计划乘马车旅行.他所在的国家里共有m个城市,在城市之间有若干道路相连.从某个城市沿着某条道路到相邻的城市需要乘坐马车.而乘坐马车需要使用车票,每用一张车票只可以通过一条道路.每张车 ...
- html样式
<!doctype html> <html> <head> <style id="mceDefaultStyles" type=" ...