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 ...
随机推荐
- 缓存ViewState减少网络传输
在维护 asp.net webform系统时,某些系统将控件及页面数据都存储在viewstate中,导致在频宽不够时,影响页面加载速度,此时可将viewstate 存储在服务端,减少网络传输. 重写 ...
- java finalize学习
1 finalize()调用的时机 与C++的析构函数(对象在清除之前析构函数会被调用)不同,在Java中,由于GC的自动回收机制,因而并不能保证finalize方法会被及时地执行(垃圾对象的回收时机 ...
- Mybatis plus 插入数据时将自动递增的主键手动进行赋值设置
1.首先设置好实体类:将类型设置为 @TableId(type = IdType.INPUT) 2.在插入数据前将id赋值给实体类对象即可
- Java 代码中如何调用 第三方Api
在代码中调用第三方API 获取数据 package com.example.demo.utils; import com.alibaba.fastjson.JSONObject; import lom ...
- Python基础-3 输入输出
输入输出 input输入函数 input函数:获取用户输入,保存成一个字符串.重要的话,说两遍,input函数的返回值是一个字符串类型.哪怕你输入的是个数字1,返回给你的只会是字符串"1&q ...
- Python学习第十二课——json&pickle&XML模块&OS模块
json模块 import json dic={'name':'hanhan'} i=8 s='hello' l=[11,22] data=json.dumps(dic) #json.dumps() ...
- sshd免密登陆
用途:默认情况下,当A主机(1.1.1.1)远程通过ssh命令登陆到B主机(2.2.2.2)上,需要输入B主机的密码.免密登陆的效果为,A通过ssh命令登录到B时,不需要输入密码就可以登录,便于管理. ...
- get方法和load方法的区别
get方法的特点 get方法采用的是立即检索策略(查询):执行到这行的时候,马上发送SQL查询 get方法查询后返回的是真实对象的本身 load方法的特点 load方法采用的是延 ...
- rarlinux安装和使用
rarlinux安装和使用
- 5.使用Redis+Flask维护动态Cookies池
1.为什么要用Cookies池? 网站需要登录才可爬取,例如新浪微博 爬取过程中如果频率过高会导致封号 需要维护多个账号的Cookies池实现大规模爬取 2.Cookies池的要求 自动登录更新 定时 ...