立志用最少的代码做最高效的表达


PAT甲级最优题解——>传送门


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:
KN​1a​N1N2aN2…N​KaNKK N​1 a​N1 N2 aN2 … N​K aNKKN​1a​N1N2aN2…N​KaNK where K is the number of nonzero terms in the polynomial, N​iN​iN​i and aNi​​(i=1,2,⋯,K)aNi​​ (i=1,2,⋯,K)aNi​​(i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤101≤K≤101≤K≤10,0≤NK<⋯<N​2<N1≤10000≤NK<⋯<N​2<N1≤10000≤NK<⋯<N​2<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


注意要点:
1、如果相加后总多项式为0,则输出0
2、如果某一项为0,则不输出


#include<bits/stdc++.h>
using namespace std;
double s[1010];
int main() {int k1; cin >> k1; while(k1--) {int x; double d; cin >> x >> d;s[x] += d;}cin >> k1; while(k1--) {int x; double d; cin >> x >> d;s[x] += d;}int num = 0;for(int i = 1009; i >= 0; i--) if(s[i] != 0) num++; if(num == 0) cout << 0;else {cout << num;for(int i = 1009; i >= 0; i--) {if(s[i] != 0) printf(" %d %.1lf", i, s[i]);}}putchar('\n');return 0;
}

耗时

1002 A+B for Polynomials (25分)_29行代码AC相关推荐

  1. 【附超时原因】1055 The World‘s Richest (25 分)_42行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Forbes magazine publishes every year its list of billionaires bas ...

  2. 【简便解法】1090 危险品装箱 (25分)_33行代码AC

    立志用最少的代码做最高效的表达 PAT乙级最优题解-->传送门 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题 ...

  3. 【详细解析】1080 MOOC期终成绩 (25分)_45行代码AC

    立志用更少的代码做更高效的表达 PAT乙级最优题解-->传送门 对于在中国大学MOOC(http://www.icourse163.org/ )学习"数据结构"课程的学生,想 ...

  4. 案例4-1.6 树种统计 (25 分)_18行代码AC

    立志用最少的代码做最高效的表达 随着卫星成像技术的应用,自然资源研究机构可以识别每一棵树的种类.请编写程序帮助研究人员统计每种树的数量,计算每种树占总数的百分比. 输入格式: 输入首先给出正整数N(≤ ...

  5. 1097 Deduplication on a Linked List (25 分)_35行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given a singly linked list L with integer keys, you are supposed ...

  6. 【题意+分析】1071 Speech Patterns (25 分)_27行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 People often have a preference among synonyms of the same word. F ...

  7. 【题意+分析】1067 Sort with Swap(0, i) (25 分)_24行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given any permutation of the numbers {0, 1, 2,-, N−1}, it is easy ...

  8. 【最后测试点超时】1063 Set Similarity (25 分)_22行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given two sets of integers, the similarity of the sets is defined ...

  9. 【最简解法】1048 Find Coins (25 分)_18行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Eva loves to collect coins from all over the universe, including ...

最新文章

  1. javascript 事件冒泡 和 冒泡事件阻止
  2. java第三方接口对接_调用多个第三方接口哪一种方案更好?
  3. 【django】数据库操作-增 删 改
  4. mysql时间函数总结_MySQL 日期时间函数常用总结
  5. 特殊表情存数据库处理
  6. C#后台调用跨域MVC服务,带Cookie验证
  7. JAVA中对集合排序
  8. dis的前缀单词有哪些_前缀dis-dis和un和im前缀-un和dis前缀的区别
  9. php k线公式源码,发个珍藏了N久的波浪主图公式(公式 指标 源码)(演示图)-其他软件公式 -程序化交易(CXH99.COM)...
  10. eclipse调成黑色主题背景(老版本适用)
  11. mysql 关闭远程_禁止MySQL root远程访问
  12. HITCON-trainning寒假做题记录
  13. Python实例之利用h5py库保存数据集
  14. Mask RCNN 实战(二)--像黑镜一样屏蔽图片和视频中的人和物体
  15. 食品类小程序有哪些?这3款小程序推荐给你
  16. WPS 加载项开发说明
  17. MFC 屏蔽ESC键和ENTER键关闭对话框的方法
  18. 中文分词_数据分析之中文分词
  19. C1认证学习十四、十五(算法常识、HTML Head 头)
  20. HYSBZ 2565 最长双回文串

热门文章

  1. 《MySQL实战45讲》实践篇 24-29 学习笔记 (主备篇)
  2. ProtoBuf的使用以及原理分析
  3. 什么是真正的架构设计?
  4. 通过Java反编译揭开一些问题的真相
  5. LeetCode 股票买卖问题
  6. 视频内容理解在手淘逛逛中的应用与落地
  7. 双双拿下赛道全部指标最佳 | 腾讯新一代VAV1携手V265亮相MSU编码器大赛
  8. 这才是真正的 Git——分支合并
  9. ISO base media file format---iso 基础媒体文件格式(专业名称)
  10. PyTorch GPU安装指南 (Ubuntu 16.04 anaconda cuda8.0 cuDNN6.0)