题意:多项式相乘,合并同类项后输出每一项的系数。

题目链接: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的更多相关文章

  1. PAT1009:Product of Polynomials

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. pat1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. django-实现登录短信验证

    功能演示 核心任务 前端功能: 点击按钮Ajax调用发送验证码功能 输完验证码后Ajax调用验证功能 后端功能: 功能1:发送验证码功能 功能2:验证码检查 后台核心逻辑(不需要手写) 功能3:发短信 ...

  2. Python 爬取 热词并进行分类数据分析-[简单准备] (2020年寒假小目标05)

    日期:2020.01.27 博客期:135 星期一 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] 所有相关跳转: a.[简单准备](本期博客) b.[云图制作+数据导入] ...

  3. mysql操作之密码的那点小事

    mysql 修改密码的2种方式: 进入mysql库的user表中修改 update mysql.user password = password("新密码") where 条件; ...

  4. Spring注解@Qualifier、@Autowired、@Primary

    @Qualifier 1.当一个接口有多个实现类,且均已注入到Spring容器中了,使用@AutoWired是byType的,而这些实现类类型都相同,此时就需要使用@Qualifier明确指定使用那个 ...

  5. 第2节 Scala中面向对象编程:7、继承的概念以及override和super关键字;8、isInstanceOf 和 asInstanceOf关键字

    6.3.   Scala面向对象编程之继承 6.3.1.     Scala中继承(extends)的概念 Scala 中,让子类继承父类,与 Java 一样,也是使用 extends 关键字: 继承 ...

  6. ardrino#串口控制led

    void setup() { pinMode(D6, OUTPUT); digitalWrite(D6,HIGH); Serial.begin(); } void loop() { String st ...

  7. [转]简单总结一下解决 添加 inline-block 后多出来的空隙

    添加 inline-block 后: 查询.借鉴的原网址:http://www.zhangxinxu.com/wordpress/?p=2357 html 结构: <ul class=" ...

  8. iOS性能优化-内存优化

    https://blog.csdn.net/a184251289/article/details/82589128 2018年09月10日 14:25:31 xingshao1990 阅读数:328 ...

  9. 高手教大家如何配置JVM参数

    /usr/local/jdk/bin/java -Dresin.home=/usr/local/resin -server -Xms1800M -Xmx1800M -Xmn300M -Xss512K ...

  10. 跨服务器的SQL语句如何书写

    select  *  into  本地库名..表名  from  OPENDATASOURCE(                  'SQLOLEDB',                  'Data ...