1002. A+B for Polynomials (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

思路:

简单题目。注意格式。如果某一项系数为0,不输出。最后一种情况,没有存在项,输出"0\n"

源代码:

 #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int na,nb;
scanf("%d",&na);
int flag[]={};
double res[]={};
int index;double data;
for(int i=;i<na;++i) {
scanf("%d %lf",&index,&data);
flag[index]=;
res[index]+=data;
}
scanf("%d",&nb);
for(int i=;i<nb;++i) {
scanf("%d %lf",&index,&data);
flag[index]=;
res[index]+=data;
}
int cnt=;
for(int i=;i<=;++i) {
if(flag[i]&&fabs(res[i])>1e-)
cnt++;
}
if(cnt==) {
printf("");
} else {
printf("%d ",cnt);
}
for(int i=;i>=;--i) {
if(flag[i]&&fabs(res[i])>1e-) {
printf("%d %.1lf",i,res[i]);
cnt--;
if(cnt==) {
break;
} else {
printf(" ");
}
}
}
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 Each input file con ...

  2. 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 ...

  3. PAT 1002 A+B for Polynomials(map模拟)

    This time, you are supposed to find A+B where A and B are two polynomials(多项式). Input Each input fil ...

  4. PAT 甲级1002 A+B for Polynomials (25)

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  5. 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 ...

  6. 【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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 虚拟专用网VPN

    1. 三个专用地址块: (1)10.0.0.0到10.255.255.255 (2)172.16.0.0到172.31.255.255 (3)192.168.0.0到192.168.255.255 2 ...

  2. 开发手机APP的神器 --- ionic

      前  言          在如今的生活中,手机已经与我们的生活紧紧的联系在了一起.而手机APP更是其中,重要的一环.今天,影子就为大家介绍一种开发手机APP的超级神器---ionic. ioni ...

  3. MySQL(十六)之MySQL用户管理

    一.MySQL用户管理概述 MySQL是一个多用户的数据库,MYSQL的用户可以分为两大类: 超级管理员用户(root),拥有全部权限 普通用户,由root创建,普通用户只拥有root所分配的权限 二 ...

  4. 在CentOS 7.3 中安装 NVIDIA GT730 显卡驱动

    主机: Dell OptiPlex 390 MT (i5) 系列: 显卡: 技嘉(GIGABYTE) GV-N730D5-2GI 902MHz/5000MHz 2GB/64bit GDDR5 显卡 ( ...

  5. Java基础笔记3

    控制语句 1. if语句 if(条件){ //如果条件成立,则运行该大括号内的内容. } if(条件){ //如果条件成立,则运行该大括号内的内容. }else{ //如果条件不成立,则运行该大括号内 ...

  6. 深度学习系列 Part (2)

    1. 神经网络原理 神经网络模型,是上一章节提到的典型的监督学习问题,即我们有一组输入以及对应的目标输出,求最优模型.通过最优模型,当我们有新的输入时,可以得到一个近似真实的预测输出. 我们先看一下如 ...

  7. Building roads

    Building roads Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  8. 常用meta整理[转载]

    < meta > 元素 概要 标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他web ...

  9. CSS与JS中的相对路径引用

    javascript和css文件中采用相对路径,其基准路径是完全不同的. 1.javascript引用资源(比如图片)相对路径是以宿主路径(被引用的网页比如你在首页index.php引用了某js文件, ...

  10. pie.htc 在IE下不起作用~~~

    一直用的IE11 然后选择其中的兼容模式来测试IE 7~10的情况. 最近由于客户要求 圆角阴影兼容IE,只能选择PIE.HTC的方案. 但是反复测试发现不起作用. 官方文档的几种说明: 1. pie ...