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 ...
随机推荐
- CHTools-OC版本目录介绍
1.CHOCBase 这里主要讲的是Objective-C语言的基础语法. 2.CHViewControllers 3.CHNS类 5.CHUI类 这里是CHUI类的集合,用于处理界面显示,其中包含部 ...
- 通知类型 重点: 环绕通知 (XML配置)
前置通知:在切入点方法执行之前执行 <aop:before method="" pointcut-ref="" ></aop:before&g ...
- 【转】Linux将composer的bin目录放到PATH环境变量中
将composer的bin目录放到PATH环境变量中 使用composer global config bin-dir --absolute查看composer的bin目录 输出类似 Changed ...
- 启动HBase脚本start-hbase.sh时报Class path contains multiple SLF4J bindings.解决方法
1. 使用start-hbase.sh启动HBase时报Class path contains multiple SLF4J bindings.错误,原因是jar包冲突导致的.所以,对于和Hadoop ...
- java.text.ParseException: Failed to parse date ["未知']
先把"未知"替换为"" 直接new 出来的Gson 对象是无法解析为""的Date属性的,需要通过GsonBuilder来进行创建 Gson ...
- 9、OpenCV Python 边缘保留滤波
__author__ = "WSX" import cv2 as cv import numpy as np # 边缘保留滤波 十分重要(美颜的核心) # 高斯双边模糊(考虑到了像 ...
- 通过IDEA及hadoop平台实现k-means聚类算法
由于实验室任务方向变更,本文不再更新~ 有段时间没有操作过,发现自己忘记一些步骤了,这篇文章会记录相关步骤,并随时进行补充修改. 1 基础步骤,即相关环境部署及数据准备 数据文件类型为.csv文件,e ...
- 以Tkinter模块来学习Python实现GUI(图形用户界面)编程
tk是什么:它是一个图形库,支持多个操作系统,使用tcl语言开发的.tkinter是Python内置的模块, 与tk类似的第三方图形库(GUI库)还有很多,比如:Qt,GTK,wxWidget,wxP ...
- kibana启动调试
在windows的命令行窗口中,将路径制定到kibana的源代码bin目录中,然后执行 kibana.bat --dev --no-base-path 需要注意的是kibana.yml中的配置文件需要 ...
- jquery each循环,实现break和continue的功能
break----用return false; continue --用return ture;