题意:

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

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. redis环境搭建学习笔记

    学习环境为windows.java环境 一.学习教程: 1.菜鸟教程:http://www.runoob.com/redis/redis-tutorial.html 2.redis中文网:http:/ ...

  2. 「JSOI2015」最小表示

    「JSOI2015」最小表示 传送门 很显然的一个结论:一条边 \(u \to v\) 能够被删去,当且仅当至少存在一条其它的路径从 \(u\) 通向 \(v\) . 所以我们就建出正反两张图,对每个 ...

  3. 关于原生,webapp,hybird(混合)

    链接:https://www.jianshu.com/p/839748d571b2 链接2:https://www.jianshu.com/p/6d5f32aa5dda

  4. WLC license管理

    关于控制器的license,可以参考对应平台的Datasheet: Cisco 2504 WLC Cisco 3504 WLC Cisco 5508 WLC Cisco 5520 WLC Cisco ...

  5. [蓝桥杯2017初赛]青蛙跳杯子 BFS

    题目描述 X星球的流行宠物是青蛙,一般有两种颜色:白色和黑色. X星球的居民喜欢把它们放在一排茶杯里,这样可以观察它们跳来跳去. 如下图,有一排杯子,左边的一个是空着的,右边的杯子,每个里边有一只青蛙 ...

  6. IDEA启动报错-java.net.BindException: Address already in use: bind

    启动IDEA报错日志如下: Internal error. Please refer to http://jb.gg/ide/critical-startup-errors java.net.Bind ...

  7. 操作系统OS - 阻塞(Blocking)非阻塞(Non-Blocking)与同步(Synchronous)异步(Asynchronous)

    参考: http://blog.jobbole.com/103290/ https://www.zhihu.com/question/19732473/answer/23434554 http://b ...

  8. 调用webservice服务(通过反射的方式动态调用)

    调用 ";//系统类别 var jkxlh = "";//接口序列号 var jkid = "68W05";//接口id string WriteXm ...

  9. ModBus的小于3.5S间隔的理解

    modbus协议中规定:至少3.5个字符传输时间的停顿间隔时间标志了消息的结束. 我的理解如下:约定参数:9600bps,8数据位,无奇偶校验,1起始位,1停止位. 9600bps代表在9600的波特 ...

  10. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(2)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...