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 ...
随机推荐
- linux_思想
linux有哪些重要的思想? 1. 做的越多错的越多 2. 纸包不住火 3. 操作重要文件前备份,操作后查看结果 4. 看到命令输出结果,可能命令有个选择直接获得对应值 5. 先定行,再定列
- j2e应用相关技术
j2e应用相关技术 轻量级j2e应用以传统的jsp作为变现层技术,以一系列开源框架作为MVC层,中间件,持久层解决方案,并将这些开源框架有机组合在一起,使得j2e具有高度的可扩展性,可维护性. ser ...
- 【转】fread函数详解
“fread”以二进制形式,从文件读出数据. 语法1:[a,count]=fread(fid,size,precision) 语法2:[a,count]=fread(fid,size,precisio ...
- 你可能不知道的.Net Core Configuration
目录 执行原理 环境变量 Spring Cloud Config Server 挂卷Volume Config Server vs Volume 执行原理 1. 配置读取顺序:与代码先后顺序一致. p ...
- adb命令介绍与使用
DB的概念 adb的全称为Android Debug Bridge,是起到调试桥的作用.通过adb,我们可以在ecplise中方便的通过DDMS来调试Android程序,其实他就是一个debug工具. ...
- [DeeplearningAI笔记]改善深层神经网络1.4_1.8深度学习实用层面_正则化Regularization与改善过拟合
觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.4 正则化(regularization) 如果你的神经网络出现了过拟合(训练集与验证集得到的结果方差较大),最先想到的方法就是正则化(re ...
- SQLServer2008修改sa密码的方法与SQL server 2008数据库的备份与还原
sa密码的修改转载自:http://blog.csdn.net/templar1000/article/details/20211191 SQL server 2008数据库的备份与还原转自 :htt ...
- centos 下安装 Jre 及 selenium
下载软件包 下载链接: jre-7u55-linux-i586.tar.gz : http://pan.baidu.com/s/14cjds selenium-server-standalone-2. ...
- React入门教程
做前端的人都知道,目前热门前端的框架是 VAR => Vue,Anglur,React. 而如果说最热门的前端框架是谁,毫无悬念是 React React 是由 Facebook 主导开发的一个 ...
- iOS-属性字符串添加下划线、删除线
常用到的属性字符串 ///定义属性字符串NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithStrin ...