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 ...
随机推荐
- 一道360 crackme的破解
该crackme主要实现都在so中,用ida加载libqihoo.so,出现以下错误 第一个错误说明是节区头部表格的表项大小错误,第二个错误是指节区头部表格的大小或偏移值错误.不管它,点击“Yes”继 ...
- 从LINQ开始之LINQ to Objects(上)
LINQ概述 LINQ,语言集成查询(Language Integrated Query),它允许使用C#或VB代码以查询数据库相同的方式来操作不同的数据源. LINQ体系结构 从上图可以看出,LIN ...
- 使用sed替换一行内多个括号内的值
1. 括号在同一行 # cat test2good morning (good afternoon) (good evening) (goodgood) (good morning) # cat se ...
- MathUtils
package com.yqw.java.util;/** * 数字转换工具 */public class MathUtils { /** * short转byte */ ...
- 渗透测试,form对象类型转换,简单demo
最近公司的项目在进行国家某行业的安全检测,涉及到项目安全渗透等方面的问题: 参与项目的渗透等改造,是一个机遇与挑战,今后对与项目安全等方面会思考更多: 下面说说form表单对象提交,为了防止抓包,后台 ...
- oracle case when及decode的用法
case ... when 语句 1) CASE column_name WHEN value1 THEN resutl1,... [ ELSE result ] END select name , ...
- 记React+.NetCore API实现动态列导出
1.效果演示 2.用到的第三方类库 前端:React,Dva,Antd 后端:ASP.NET CORE,System.Linq.Dynamic.Core,EPPlus.Core 3.基本思路 第一:E ...
- HBuilder打包Android apk 支付不了问题解决
第一步: 安卓生成自有证书:到JRE的bin目录下,运行keytool命令:cd C:\Program Files\Java\jre1.8.0_91\binkeytool -genkey -alias ...
- ssh 设置私钥实现两台linux主机无密码访问
在服务器主机上(称为A主机) 创建公钥与私钥: ssh-keygen -t rsa 一路回车,如果想设置密码短语,在提示 passphrase 的时候设置密码短语 查看生成的公钥及私钥: ls ~/. ...
- Zookeeper启动时报8080端口被占用
zookeeper启动时报8080 端口被占用,导致启动失败.特别是服务器上部署了tomcat服务时需要注意. 通过查看zookeeper的官方文档,发现有3种解决途径: (1)删除jetty. (2 ...