【PAT甲级】1009 Product of Polynomials (25 分)
题意:
给出两个多项式,计算两个多项式的积,并以指数从大到小输出多项式的指数个数,指数和系数。
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 分)的更多相关文章
- 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 ...
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
- 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 ...
- 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) 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
PATA1009 Product of Polynomials Output Specification: For each test case you should output the produ ...
- 【PAT】1009. Product of Polynomials (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- 1009 Product of Polynomials (25分) 晚上脑子就是容易僵住
#include<iostream> using namespace std; struct { int a; double b; }poly[1001]; double a[2001]; ...
随机推荐
- npm报错This is probably not a problem with npm. There is likely additional logging
使用webstorm开发时,遇到npm 报错,于是尝试了如下所有的方法,不完全统计. https://blog.csdn.net/liu305088020/article/details/791823 ...
- Fluent_Python_Part1序幕,01-data-model, 数据模型
01-data-model/frenchdeck.py 1. Python解释器碰到特殊的句法时,会使用__特殊方法__去激活一些基本的对象操作. 特殊方法的存在是为了被解释器用的.没有my_obje ...
- sqlmap 扫描注入漏洞
.检测是否存在漏洞: sqlmap -u .获取数据库信息: sqlmap -u --dbs .数据库表信息: sqlmap -u -D security --tables .表中字段信息 sqlma ...
- Linux安装Redis服务
下载:wget http://download.redis.io/releases/redis-5.0.5.tar.gz 解压:tar -zxvf redis-5.0.5.tar.gz 进入redi ...
- synchronized锁机制的实现原理
Synchronized 锁机制的实现原理 Synchronized是Java种用于进行同步的关键字,synchronized的底层使用的是锁机制实现的同步.在Java中的每一个对象都可以作为锁. J ...
- 【CSS属性#1】
" 目录 一.宽和高 二.字体属性 1. 文字字体 font-famlly 2. 字体大小 font-size 3. 字重(粗细) font-weight 4. 文本颜色 color 三.字 ...
- mcast_get_ttl函数
#include <errno.h> #include <net/if.h> #include <sys/socket.h> #include <netine ...
- python重要的日志模块logging
一,logging模块简介 logging模块是Python内置的标准模块,主要用于输出运行日志,可以设置输出日志的等级.日志保存路径.日志文件回滚等:相比print,具备如下优点: 1.可以通过设置 ...
- maplotlib python 玩具绘图 横向纵向条状图
from matplotlib import font_manager#解决zh-han图形汉字乱码 my_font = font_manager.FontProperties(fname=" ...
- ASP.NET Core搭建多层网站架构【15-扩展之使用Obfuscar混淆加密保护代码】
2020/02/03, ASP.NET Core 3.1, VS2019, Obfuscar 2.2.25 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[15-扩展之使 ...