PAT 1009 Product of Polynomials 模拟
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 coeficients(系数), 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
题目意思:给你两个多项式A和B,求A*B的结果。
解题思路:两个多项式相乘,系数coeficients相乘,指数exponents相加,模拟一下即可。这里由于指数是连续的,系数不连续且是小数,所以可以用数组来保存多项式,指数作为数组下标,系数保存到数组中。最后按照指数递减的顺序输出所有的不为0的项即可。
decimal
adj. 小数的;十进位的
n. 小数
Product
n. 乘积、产物
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<map>
using namespace std;
int main()
{
int n1,n2,cnt=;
int i,j,e;
double c;
double a[]={0.0},ans[]={0.0};
scanf("%d",&n1);
for(i=;i<n1;i++)
{
scanf("%d %lf",&e,&c);
a[e]=c;
}
scanf("%d",&n2);
for(i=;i<n2;i++)
{
scanf("%d %lf",&e,&c);
for(j=;j<;j++)
{
if(a[j]!=)
{
if(a[j]*c>10.0)
{
ans[j+e+]+=(a[j]*c)/10.0;//产生进位
}
else
{
ans[j+e]+=a[j]*c;//系数相乘,指数相加
}
}
}
}
for(i=;i<;i++)
{
if(ans[i]!=)
{
cnt++;
}
}
printf("%d",cnt);//所有不为0的项数数量
for(i=-;i>=;i--)
{
if(ans[i]!=)
{
printf(" %d %.1f",i,ans[i]);
}
}
return ;
}
PAT 1009 Product of Polynomials 模拟的更多相关文章
- 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 ...
- PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值
题目 This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: E ...
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
- 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 ...
- 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 ...
- PATA 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 po ...
随机推荐
- 1. 初探--prometheus调研
一.基本概念 Prometheus 是由前 Google 工程师从 2012 年开始在 Soundcloud 以开源软件的形式进行研发的系统监控和告警工具包,自此以后,许多公司和组织都采用了 Prom ...
- CCF-CSP题解 201703-3 Markdown
要求实现简易的Markdown到Html格式的转换. 主要就是字符串处理.以空行划分各个区块,区块内部字符的输出用一个\(print\_buf\)实现,至于强调和超链接的嵌套,则可以递归实现. 注意用 ...
- 《MySQL数据库》MySQL数据库安装(windows)
MySQL安装包和操作工具 链接: https://pan.baidu.com/s/1BTfrHwVR1uNBuB_E27N55g 提取码: dhbv 1.首先解压文件包,我这解压到E:\instal ...
- sqlserver 行转列、字符串行转列、自动生产行转列脚本
行转列,老生常谈的问题.这里总结一下网上的方法. 1.生成测试数据: CREATE TABLE human( name ), --姓名 norm ), --指标 score INT , --分数 gr ...
- python多线程编程—同步原语入门(锁Lock、信号量(Bounded)Semaphore)
摘录python核心编程 一般的,多线程代码中,总有一些特定的函数或者代码块不希望(或不应该)被多个线程同时执行(比如两个线程运行的顺序发生变化,就可能造成代码的执行轨迹或者行为不相同,或者产生不一致 ...
- JS---案例:移动元素,封装动画函数
案例:移动元素,封装动画函数 1. div要移动,要脱离文档流---position:absolute 2. 如果样式的代码是在style的标签中设置,外面是获取不到 3. 如果样式的代码是在styl ...
- Dynamics 365 Portal 修改注册页面及Profile页面
一,Profile页面 客户要求在Portal Profile页面上添加性别字段,通过查看源代码发现,中间的联系人信息部分是引用的CRM中Contact实体的Portal Web Form表单,直接把 ...
- 「SAP技术」SAP MM 明明有维护源清单,还是不能下PO?
SAP MM 明明有维护源清单,还是不能下PO? 下午收到用户报错说,创建采购订单失败,报错 :Material ### not included in source list despite sou ...
- 如何向小姐姐解释SQL和NoSQL之间的区别
最近,在Medium上出现了一个采访问题:如何向奶奶解释SQL和NoSQL之间的区别.我认为作者使用自己的结构化家谱来比较sql和nosql之间的差异.写作非常好,但是有点尴尬.面试官没有时间听你的话 ...
- linux部署.net Core项目
首篇笔记,多多关照.方便回忆和给新手指导,大神绕道 首先在Linux系统部署.net Core项目首先准备一个Linux系统的服务器,百度云,阿里云都行. 1.net core 部署在Linux系统上 ...