思路:就是两个多项式做加法–指数相同的相加即可,输出的时候按照指数递减输出,并且系数为0的项不输出。


AC代码

#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1000+5;
float a[maxn];
vector<pair<int, float> > ans;
int t;

int main() {
    int k, x;
    float y;
    t = -1;
    for(int i = 0; i < maxn; i++) {
        a[i] = 0.0;
    }
    for(int i = 0; i < 2; i++) {
        scanf("%d", &k);
        for(int j = 0; j < k; j++) {
            scanf("%d%f", &x, &y);
            a[x] += y;
            t = max(t, x);
        }
    }
    for(int i = t; i >= 0; i--) {
        if(a[i] != 0.0) {
            ans.push_back(make_pair(i, a[i]));
        }
    }
    printf("%d", ans.size());
    for(int i = 0; i < ans.size(); i++) {
        printf(" %d %.1f", ans[i].first, ans[i].second);
    }
    printf("\n");
    return 0;
}

如有不当之处欢迎指出!

PAT 1002. A+B for Polynomials的更多相关文章

  1. PAT 1002. A+B for Polynomials (25) 简单模拟

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

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

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

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

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

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

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

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

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

随机推荐

  1. Go_Hello word

    与Go相关直接命令有哪些? go get    获取远程包 go run    直接运行程序 go bulid  测试编译 go fmt    格式化代码 go install       编译包文件 ...

  2. mybatis分页+springmvc+jsp+maven使用步骤

    作者注:本文主要用于个人学习.复习.同时欢迎指导讨论 1,添加maven依赖<dependency>         <groupId>com.github.miemiedev ...

  3. 转-CSS padding margin border属性详解

    原文链接:http://www.cnblogs.com/linjiqin/p/3556497.html 图解CSS padding.margin.border属性W3C组织建议把所有网页上的对像都放在 ...

  4. gd库的安装

    gd库简介 主要用途编辑 在网站上GD库通常用来生成缩略图,或者用来对图片加水印,或者用来生成汉字验证码,或者对网站数据生成报表等.在PHP处理图像,可使用GD库,而GD库开始时是支持GIF的,但由于 ...

  5. Java多线程优化方法及使用方式

    一.多线程介绍 在编程中,我们不可逃避的会遇到多线程的编程问题,因为在大多数的业务系统中需要并发处理,如果是在并发的场景中,多线程就非常重要了.另外,我们在面试的时候,面试官通常也会问到我们关于多线程 ...

  6. How to get started with GIT and work with GIT Remote Repo

    https://www.ntu.edu.sg/home/ehchua/programming/howto/Git_HowTo.html#zz-7. 1.  Introduction GIT is a ...

  7. Erlang调度器细节探析

    Erlang调度器细节探析 Erlang的很多基础特性使得它成为一个软实时的平台.其中包括垃圾回收机制,详细内容可以参见我的上一篇文章Erlang Garbage Collection Details ...

  8. ABAP更换请求

    当创建的程序或表操作失误存储在其他的请求下边如何更换请求呢? 事务代码:SE09 双击请求号,复制存储错误的对象 打开一个新窗口,双击正确的请求,点击修改,将复制的对象粘贴在正确的请求下 将错误的请求 ...

  9. Effective Java 第三版——31.使用限定通配符来增加API的灵活性

    Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...

  10. Springboot security cas源码陶冶-FilterSecurityInterceptor

    前言:用户登录信息校验成功后,都会获得当前用户所拥有的全部权限,所以对访问的路径当前用户有无权限则需要拦截验证一发 Spring security过滤器的执行顺序 首先我们需要验证为啥FilterSe ...