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 ...
随机推荐
- Vagrant 安装使用
先安装虚拟机 https://www.virtualbox.org/ 再安装 https://www.vagrantup.com/ 1.nginxhttp://nginx.org/download/ ...
- 设计模式课程 设计模式精讲 3-11 合成复用原则coding
1 课堂概念 1.0 继承关系的选择 1.1 起名 1.2 定义 1.3 组合聚合优缺点 1.4 继承优缺点 1.5 组合聚合区别 2 代码演练 2.1 反例 2.2 正例 3 疑问解答3.1 疑问解 ...
- 【LOJ3087】「GXOI / GZOI2019」旅行者
题意 给定一个 \(n\) 个点 \(m\) 条边的的有向图,给出 \(k\) 个关键点,求关键点两两最短路的最小值. \(n\le 10^5, m\le 5\cdot 10^5\). 题解 二进制分 ...
- 1003 Emergency (25分) 求最短路径的数量
1003 Emergency (25分) As an emergency rescue team leader of a city, you are given a special map of ...
- C. Swap Letters 01字符串最少交换几次相等
C. Swap Letters time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- PaperReading20200227
CanChen ggchen@mail.ustc.edu.cn Neural Predictor for Neural Architecture Search Motivation: Curren ...
- loadrunner 接口测试实战
直接上代码: web_reg_save_param("Name", //这个函数是为了获取服务器返回的值.我这个接口的返回值是这样子的 //将服务器返回的值放在Name里,Na ...
- 发送邮件#Python
import yagmailusername='11@qq.com' #发件人邮箱qq='zhezlqiggd' #授权码,QQ邮箱可在设置账户获得mail_server='smtp.qq.com' ...
- Python学习笔记004
变量 变量的命名规则1. 要具有描述性2. 变量名只能_,数字,字母组成,不可以是空格或特殊字符(#?<.,¥$*!~)3. 不能以中文为变量名4. 不能以数字开头,下划线或者小写字母开头,驼峰 ...
- CF1285D Dr. Evil Underscores
挂个链接 Description: 给你 \(n\) 个数 \(a_1,a_2,--,a_n\) ,让你找出一个 \(x\) ,使 \(x\) 分别异或每一个数后得到的 \(n\) 个结果的最大值最小 ...