PAT 1002. A+B for Polynomials
思路:就是两个多项式做加法–指数相同的相加即可,输出的时候按照指数递减输出,并且系数为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的更多相关文章
- PAT 1002. A+B for Polynomials (25) 简单模拟
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【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 ...
随机推荐
- c:if true、false都显示
看了半天,最后发现jstl标签库没有引入! <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core ...
- 在 Tomcat 上配置虚拟主机
.Tomcat 服务器的server.xml文件 (1)Tomcat 组件 Tomcat服务器是由一系列可配置的组件构成,其中核心组件是 Catalina Servlet 容器,它是所有其他 To ...
- linkin大话面向对象--构造器详解
对象的产生格式:类名称 对象名 = new 类名称(); 因为有(),所以是方法,实际上它就是构造方法,并且是非私有的构造方法.如:CellPhone cp = new CellPhone( ...
- asp.net core如何自定义端口/修改默认端口
.net core运行的默认端口是5000,但是很多时候我们需要自定义端口.有两种方式 写在Program的Main方法里面 添加 .UseUrls() var host = new WebHostB ...
- 尝试Spring Data Jpa--告别CRUD
前言 说到我们的web开发架构分层中,持久层是相对底层也是相对稳定的一层,奠定好根基后,我们才能专注于业务逻辑和视图开发.而自从ORM思想蔓延开来后,全自动ORM的Hibernate和半自动ORM的M ...
- MySQL--当事务遇到DDL命令
众所周知MySQL的DDL语句是非事务的,即不能对DLL语句进行回滚操作,哪在事务中包含DDL语句会怎样呢? 如: #禁用自动提交 set autocommit=off; #创建tb1 create ...
- oracle pl/sql如何定义变量
目的:如何在pl/sql中定义基本类型,引用类型,记录型变量? 以下plsql程序用的scott用户的dept,emp表. 定义基本类型的变量 set serveroutput on ; --使用基本 ...
- windows上搭建svn 、 Eclipse上安装svn插件 、 eclipse中如何使用svn
折腾了许久终于搞出来了. svn搭建 一.svn概述 SVN就是用于多个人共同开发同一个项目,共用资源的目的,该文描述了把svn搭建在本地上,和搭建在Eclipse4.5.2上. 二.svn分类 分为 ...
- Django中url的生成过程详解
在前面我们知道,Django启动之前会执行admin.py中的autodiscover()方法. def autodiscover(): autodiscover_modules('admin', r ...
- hexo建立github,gitcafe博客并实时同步的要点
把hexo博客的源码和生成的页面实时同步到github和gitcafe. 用搜索引擎搜索"github 博客"等关键字会出现大量很好的文章教小白一步步搭建.我这里列出一些关键点,希 ...