题意:

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

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. awk函数实现将点分式形式的掩码转换为十进制形式的掩码

    在用awk处理文本时,需要将源数据为点分式形式的掩码转换为十进制形式的掩码,下边的函数可简单实现: 转换功能函数cdr2mask function cdr2mask(mask_point) { num ...

  2. python中 使用join()方法

    使用join()方法 对各种数据类型中元的素进行合并拼接 "连接符".join(列表或元组或字符串或字典) 返回的是一个使用连接符进行拼接的字符串 如果对象是列表,元组,就是以一个 ...

  3. spark streaming读取kakfka数据手动维护offset

    在spark streaming读取kafka的数据中,spark streaming提供了两个接口读取kafka中的数据,分别是KafkaUtils.createDstream,KafkaUtils ...

  4. 用xshell连接VMware虚拟机中安装的Centos7系统

    首先要保证你安装的Centos7系统的网路适配器使用的桥接模式,这个模式允许你安装再虚拟机中的Centos系统有一个自己的ip地址. 然后再虚拟机中登录你的Centos系统,用ip addr命令查看你 ...

  5. 安装pyhanlp

    安装pyhanlp pyhanlp是java写的,外层封装了python. 对于新手,在使用的时候稍有难度. 1. 下载源码 https://github.com/hankcs/pyhanlp git ...

  6. 使用ssh 初始化git一个空java工程

    1:进入git 目录 cd /home/git/repo/ 2:创建一个java工程名 mkdir qft-payment 3:进入工程 cd  qft-payment/ 4:初始化空工程 git - ...

  7. agc026F Lotus Leaves

    题目链接 题目大意 一个n*m的网格上有一些点,一个点可以跳到与其同一行或同一列的点上.给定起点和终点. 求要使起点不能跳到终点,最少撤走几个点. \(n,m\leq 100\) 解题思路 考虑将能够 ...

  8. C的精神

    信任程序员 不要妨碍程序员做需要做的事 保持语言精练简单 只提供一种方法执行一项操作 让程序运行更快, 即使不能保证其可移植性 在最后一点上, 标准委员会的用意是: 作为实现, 应该针对目标计算机来定 ...

  9. html 标签 frame

    html 标签 frame 对于html标签,一般都是在<html>标签对里包着<head>标签对和<body>标签对,body元素定义文档的主体,包含文档的所有内 ...

  10. HDU3172 Virtual Friends

    基础并查集~ #include<cstdio> #include<algorithm> #include<cstring> #include<unordere ...