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 ...
随机推荐
- netty集成springboot
一 前言 springboot 如何集成netty实现mapper调用不为null的问题让好多读者都头疼过,知识追寻者发了一点时间做了个基本入门集成应用给读者们指明条正确的集成方式,我相信,只要你有n ...
- Python 基础之面向对象之类中的方法和与类相关的魔术属性以及反射
一.类中的方法 普通方法: 没有参数,只能类调用绑定方法: (1)绑定到对象(自动传递对象参数) (2)绑定到类(自动传递参数)静态方法: 无论是类还是对象,都能调用的方法#例:class Dog() ...
- NSObject类的API介绍
这篇文章围绕的对象就是NSObject.h文件,对声明文件中的属性.方法进行必要的“翻译”. 该文件大致由两部分组成:NSObject协议和NSObject类. (一)NSObject协议 - (BO ...
- Linux命令:ping命令
ping命令:类似于windows的ping命令,用于测试网络主机ICMP请求回应的 ping选项 ping -c # # 执行次数 -w # #测试 ...
- Linux三剑客之awk精讲(基础与进阶)
第1章 awk基础入门 要弄懂awk程序,必须熟悉了解这个工具的规则.本实战笔记的目的是通过实际案例或面试题带同学们熟练掌握awk在企业中的用法,而不是awk程序的帮助手册. 1.1 awk简介 一种 ...
- AVL-Tree (平衡二叉树)
看到网上AVL-Tree大多数都是用相同的实现方式 —— 递归进行插入.删除.维护平衡等,而我比较喜欢用带父指针的数据结构,于是想了一下午,用C实现了一个迭代版的. 由于没有暂时没有好的画二叉树的工具 ...
- Webshell免杀研究
前言 不想当将军的士兵不是好士兵,不想getshell的Hacker不是好Hacker~有时候我们在做攻防对抗时经常会碰到可以上传webshell的地方,但是经常会被安全狗.D盾.护卫神.云锁等安全软 ...
- 38 java 使用标签跳出多层嵌套循环
public class Interview { public static void main(String[] args) { //使用带标签的break跳出多层嵌套循环 Boolean flag ...
- 访问docker desktop创建的Hyper-v虚拟机DockerDesktopVM
平常我们部署kubernetes ,一般都是先安装个linux操作系统,不管是centos或者ubuntu或者其他,都是我们手工操作的.安装好的这个操作系统都开启了SSH,能够远程登录访问. 但是do ...
- 提高unigui开发效率的两个方法(02)
1.编译时自己退出运行的程序. 在做unigui开发时,每次编译运行时,unigui的应用都会在后台运行,每次重新编译时都必须手工在任务栏里将应用退出才行,非常麻烦,可以在项目编译的参数里加上杀进程的 ...