1009. Product of Polynomials (25)

时间限制
400 ms

内存限制
32000 kB

代码长度限制
16000 B

判题程序
Standard

作者
CHEN, Yue

This time, you are supposed to find A*B where A and B are two polynomials.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10, 0 <= NK < ... < N2 < N1 <=1000.

Output Specification:

For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.

Sample Input

2 1 2.4 0 3.2
2 2 1.5 1 0.5

Sample Output

3 3 3.6 2 6.0 1 1.6
#include"iostream"
#include "algorithm"
#include <math.h>
#include <iomanip>
#include"string.h"
#include "vector"
using namespace std;
#define max 3000
struct Poly
{int index;//指数float factor;//系数
};int main()
{vector<double> result;int k1,k2;cin >> k1;vector<Poly> p1(k1);for(int i=0;i<k1;i++)cin >> p1[i].index >> p1[i].factor;cin >> k2;vector<Poly> p2(k2);for(int i=0;i<k2;i++)cin >> p2[i].index >> p2[i].factor;result.assign(max+1,0.0);int t=0;for(int i=0;i<k1;i++)for(int j=0;j<k2;j++){Poly p;p.index = p1[i].index+p2[j].index;p.factor = p1[i].factor*p2[j].factor;result[p.index] +=p.factor;}int k=0;for(int i=max;i>=0;i--){if(fabs(result[i])>1e-6){k++;}}cout<<k;for(int i=max;i>=0;i--){if(fabs(result[i])>1e-6){cout<<" "<<i<<" ";cout<<setiosflags(ios::fixed);cout.precision(1);cout<<result[i];}}cout<<endl;return 0;
}

  

转载于:https://www.cnblogs.com/luxiao/p/pat1009.html

浙大pat1009题解相关推荐

  1. python第六章函数课后答案_浙大PTA-Python题库 函数题(6-1~6-6)题解

    其他各章题解链接如下 浙大PTA-Python题库 编程题第一章(1-1~1-3)题解 https://blog.csdn.net/zimuzi2019/article/details/1070206 ...

  2. 浙大pythonpta作业答案_浙大PTA-Python题库 编程题第一章(1-1~1-3)题解

    注:第七章只有一道题,因为正则表达式学校尚不要求我就还没看,所以这道题解的链接是另一个大佬的 题目列表 1-1 从键盘输入两个数,求它们的和并输出 本题目要求读入2个整数A和B,然后输出它们的和. 输 ...

  3. 浙江大学pta答案python第四章_浙大PTA-Python题库 编程题第一章(1-1~1-3)题解

    其他各章题解链接如下 浙大PTA-Python题库 编程题第一章(1-1~1-3)题解 https://blog.csdn.net/zimuzi2019/article/details/1070206 ...

  4. 浙大PTA-Python题库 编程题第五章(5-1~5-11)题解

    其他各章题解链接如下 浙大PTA-Python题库 编程题第一章(1-1~1-3)题解 https://blog.csdn.net/zimuzi2019/article/details/1070206 ...

  5. 浙大PTA-Python题库 编程题第一章(1-1~1-3)题解

    其他各章题解链接如下 浙大PTA-Python题库 编程题第一章(1-1~1-3)题解 https://blog.csdn.net/zimuzi2019/article/details/1070206 ...

  6. 浙大PTA-Python题库 函数题(6-1~6-6)题解

    其他各章题解链接如下 浙大PTA-Python题库 编程题第一章(1-1~1-3)题解 https://blog.csdn.net/zimuzi2019/article/details/1070206 ...

  7. 2015浙大计算机考研,2015浙大计算机考研机试题解.pdf

    天勤论坛ACM 版块版主原创,转载请注明出处! 2012 浙江大学计算机考研机试题解 我要解决什么问题? 我要如何去解决? 编码! 特别注意:为了排序方便使用了C++函数库algorithm 中的so ...

  8. 第3章-21 判断回文字符串 (15分) PTA-python 题解 浙大版《Python 程序设计》题目集

    致读者: 博主是一名数据科学与大数据专业大三的学生,一个互联网新人,这篇文章是记录我作为python助教总结的简单题解,写博客一方面是为了记录自己的学习过程中遇到的问题和思考,一方面是希望能够帮助到很 ...

  9. 浙大PTA平台上的题目题解

    记载一些题目的代码,之后想要在b站讲题目,到时候会把录的视频上传b站.不是大佬,是蒟蒻,大佬勿喷,仅供参考,欢迎大家star,qwq. 浙大版<C语言程序设计(第3版)>题目集

最新文章

  1. led灯串怎么摆造型_一元包邮的家用LED日光灯泡,究竟是怎么做到的?
  2. 51NOD 1212 无向图最小生成树
  3. Ajax — 聊天机器人演示
  4. [工具]OFFICE插件管理工具-帮助更好地管理及使用电脑安装过的OFFICE插件
  5. centos7安装samba服务器
  6. 基于JAVA+SpringBoot+Mybatis+MYSQL的记账本管理系统
  7. mongodb,spring data api常用总结
  8. 计算机发展史观后感50字,《计算机:一部历史》读后感_1300字
  9. 随便聊聊,关于大学,未来的规划
  10. 5000字、12字 连环炮、一张图快速解决线程池
  11. 主机上没有虚拟机网络适配器VMnet8解决办法
  12. 栈 括号匹配问题(C语言)
  13. Revit二次开发_轴网快速标注
  14. 100V降压图纸 电路最简单的高压降压解决方案
  15. 带搜索框的百度地图html
  16. css设置1.5倍行高,CSS怎么控制行高?
  17. npj | 王德华/张学英等揭示荒漠啮齿动物通过“菌群-肠-肾”轴耐受高盐的机制...
  18. 在瑞典当码农 :在家上班?不加班?能干到60岁?
  19. SVPWM模块为什么会出现扇区判断错误?
  20. 陈天奇的机器学习编译课(免费)

热门文章

  1. 扩展运算符,Object.assign
  2. intelliJ idea如何安装、配置
  3. AlphaZero进化论:从零开始,制霸所有棋类游戏
  4. 《中国人工智能学会通讯》——4.27 电子数据取证理论与技术
  5. 让你的 wowza server提供 RESTful web 服务
  6. webalizer日志分析软件的安装
  7. PWA(Progressive Web App)入门系列:消息通讯
  8. ES6简单总结(搭配简单的讲解和小案例)
  9. [发布]Lucene索引分析工具Luke.Net 0.5升级版 (兼容Lucene.Net 2.9.4.1)
  10. Ubuntu 11.04解决txt文档中文乱码方法