题意:

给出两个多项式,计算两个多项式的积,并以指数从大到小输出多项式的指数个数,指数和系数。

trick:

这道题数据未知,导致测试的时候发现不了问题所在。

用set统计非零项时,通过set.size()输出非零项个数,set.count()与否来判断是否输出该项时结果第0个测试点答案错误。

用fabs(mp[i])>=0.05时结果全部正确,因为考虑到保留1位小数所以用这个语句来判断保留小数后是否非零。

问题是当去掉fabs()时采用mp[i]>=0.05结果第0个测试点答案错误。

而不管保留1位小数以后才导致的0.0直接输出非零(以下代码采用本方法)又会全部通过。

感觉题意可能引起歧义,测试点也未公开,所以有些答案不得而知,对于小数精度的判断知识又掌握甚少,为节省时间故不再深究。

希望对第0点答案错误的朋友有所帮助。

AAAAAccepted code:

 #include<bits/stdc++.h>
using namespace std;
int a[],b[];
double num1[],num2[];
map<int,double>mp;
int main(){
int n;
cin>>n;
for(int i=;i<=n;++i)
cin>>a[i]>>num1[i];
int m;
cin>>m;
for(int i=;i<=m;++i)
cin>>b[i]>>num2[i];
for(int i=;i<=n;++i)
for(int j=;j<=m;++j){
int x=a[i]+b[j];
double ans=num1[i]*num2[j];
mp[x]+=ans;
}
int cnt=;
for(int i=;i<=;++i)
if(mp[i])
cnt++;
cout<<cnt;
for(int i=;i>=;--i)
if(mp[i])
cout<<" "<<i<<" "<<setiosflags(ios::fixed)<<setprecision()<<mp[i];
return ;
}

【PAT甲级】1009 Product of Polynomials (25 分)的更多相关文章

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

  2. pat 甲级 1009. Product of Polynomials (25)

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

  3. PAT Advanced 1009 Product of Polynomials (25 分)(vector删除元素用的是erase)

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

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

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

  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

    PATA1009 Product of Polynomials Output Specification: For each test case you should output the produ ...

  8. 【PAT】1009. Product of Polynomials (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...

  9. 1009 Product of Polynomials (25分) 晚上脑子就是容易僵住

    #include<iostream> using namespace std; struct { int a; double b; }poly[1001]; double a[2001]; ...

随机推荐

  1. Hadoop3.1.1源码Client详解 : Packet入队后消息系统运作之DataStreamer(Packet发送) : 主干

    该系列总览: Hadoop3.1.1架构体系——设计原理阐述与Client源码图文详解 : 总览 在上一章(Hadoop3.1.1源码Client详解 : 写入准备-RPC调用与流的建立) 我们提到, ...

  2. mui 进度条 隐藏

    官方提供的 mui(contanier).progressbar().hide(); 并未起作用,DOM是js动态添加的,结果无法隐藏.(越使用,mui 的坑越多,陆续记录中...) 后使用下面的方法 ...

  3. python 读写函数

    1.open 使用open打开文件后一定要记得调用文件对象的close()方法.比如可以用try/finally语句来确保最后能关闭文件. file_object = open('thefile.tx ...

  4. 使用node.js实现多人聊天室(socket.io、B/S)

    通过B/S架构实现多人聊天,客户端连接服务器,发送信息,服务器接收信息之后返回给客户端. 主要是通过socket.io实现浏览器和服务器之间进行实时,双向和基于事件的通信. socket.io官方文档 ...

  5. mysql事务管理及spring声明式事务中主动异常抛出使数据库回滚

    mysql的引擎常用的有两个,一个MyISAM,另一个是InnoDB,mysql默认的为MyISAM,而InnoDB才是支持事务的.所以一般需要修改下,如何修改就不说了. 事务需要依赖数据库,好久没使 ...

  6. 20-02-27 hive表的几个问题

    1.hive表的动态分区 2.hive  表如何修改列名 3.group  by  对统计指标的影响  (group by 的本质) 4.row_number 对数据的影响

  7. 后端——框架——容器框架——spring_core——《官网》阅读笔记——初篇

    1.知识体系 spring-core的知识点大概分为以下几个部分 IOC容器 Bean的配置,XML方式和注解方式 Bean的管理,bean的生命周期,bean的作用域等等 与Bean相关联的接口和对 ...

  8. git 工具常见命令

    1.git是什么 git是分布式版本管理工具,一台电脑既可以是客户端,也可以是服务端.工作过程中可以断开网络. git中的三个概念: 1.版本库:在初始化git版本库之后会生成一个隐藏的文件, .gi ...

  9. VS2017中使用C++语言编写delay函数实现延迟

    秒级别的延时 //定义函数 void delay(int sec){ time_t start_time, cur_time; // 变量声明 time(&start_time); do { ...

  10. Codeforces Round #575 (Div. 3) 题解

    比赛链接:https://codeforc.es/contest/1196 A. Three Piles of Candies 题意:两个人分三堆糖果,两个人先各拿一堆,然后剩下一堆随意分配,使两个人 ...