Product of Polynomials
题意:多项式相乘,合并同类项后输出每一项的系数。
题目链接:https://www.patest.cn/contests/pat-a-practise/1009
分析:注意合并后系数为0,这一项就不存在了。
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
const int MAXT = 2000 + 10;
map<int, double> mp1;
map<int, double> mp2;
map<int, double> mp3;
stack<pair<int, double> > st;
int main(){
int n;
scanf("%d", &n);
int id;
double x;
while(n--){
scanf("%d%lf", &id, &x);
mp1[id] = x;
}
scanf("%d", &n);
while(n--){
scanf("%d%lf", &id, &x);
mp2[id] = x;
}
for(map<int, double>::iterator it1 = mp1.begin(); it1 != mp1.end(); ++it1){
for(map<int, double>::iterator it2 = mp2.begin(); it2 != mp2.end(); ++it2){
id = (*it1).first + (*it2).first;
mp3[id] += (*it1).second * (*it2).second;
}
}
for(map<int, double>::iterator it = mp3.begin(); it != mp3.end(); ++it){
if((*it).second == 0) continue;
st.push(pair<int, double>((*it).first, (*it).second));
}
printf("%d", st.size());
while(!st.empty()){
pair<int, double> tmp = st.top();
st.pop();
printf(" %d %.1lf", tmp.first, tmp.second);
}
printf("\n");
return 0;
}
Product of Polynomials的更多相关文章
- PAT1009:Product of Polynomials
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT 1009 Product of Polynomials
1009 Product of Polynomials (25 分) This time, you are supposed to find A×B where A and B are two p ...
- PTA (Advanced Level) 1009 Product of Polynomials
1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...
- PAT Product of Polynomials[一般]
1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...
- 1009 Product of Polynomials (25 分)
1009 Product of Polynomials (25 分) This time, you are supposed to find A×B where A and B are two pol ...
- PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)
1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...
- pat1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名
题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...
- A1009 Product of Polynomials (25)(25 分)
A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...
随机推荐
- Nginx Rewrite域名及资源重定向!(重点)
第一步:搭建Nginx服务 第二步:修改主配置文件 [root@ns2 ~]# vim /usr/local/nginx/conf/nginx.conf user nginx nginx; work ...
- 基于three.js实现特定Div容器的粒子特效封装
本文基于three.js实现特定容器的粒子特效效果,支持用户传入特定的dom对象以及粒子颜色. 效果图 移入库 <script src="jquery-1.11.3.min.js&qu ...
- SVN安装不成功,提示Invalid driver H:
本来我的SVN安装在H盘,后来我把包含H盘的硬盘下下来了,这样H盘就不存在了. 这时候我想重新安装SVN,点击安装包,结果提示Invalid driver H,怎么都不能安装成功. 这时候我去注册表里 ...
- 第七届蓝桥杯javaB组真题解析-剪邮票(第七题)
题目 /* 剪邮票 如[图1.jpg], 有12张连在一起的12生肖的邮票. 现在你要从中剪下5张来,要求必须是连着的. (仅仅连接一个角不算相连) 比如,[图2.jpg],[图3.jpg]中,粉红色 ...
- Mac. 修改bash_file
https://www.cnblogs.com/mokey/p/3542389.html
- day1-2基本数据类型
/*5种基本数据类型 1,Undefined var a; a = undefined Undefined派生自Null 2,Null(本质属于object,单独细分出来的) var a = null ...
- LeetCode简单题(一)
题目一: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组 ...
- Linux命令:ip命令
ip命令功能:配置网络属性 一.ip link 系列 ip link ip [-s] link show # 查看默认信息 ip link show eth0 ip link show ...
- 【PAT甲级】1036 Boys vs Girls (25 分)
题意: 输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数.输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前 ...
- Java垃圾回收与内存
好久没看关于java的书了, 最近, 看了James Gosling的<<Java程序设计语言>>, 做了一些读书笔记. 这部分是关于垃圾回收的. 1.垃圾回收 对象是使用ne ...