【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]; ...
随机推荐
- GO学习之 为什么选择GO
一.Go语言为并发而生 如上所述,硬件制造商正在为处理器添加越来越多的内核以提高性能.所有数据中心都在这些处理器上运行,更重要的是,今天的应用程序使用多个微服务来维护数据库连接,消息队列和维护缓存.因 ...
- Tomcat 和 JVM 性能调优总结
Tomcat性能调优: 找到Tomcat根目录下的conf目录,修改server.xml文件的内容.对于这部分的调优,我所了解到的就是无非设置一下Tomcat服务器的最大并发数和Tomcat初始化时创 ...
- opencv:图像查找表 与 颜色表
LUT 使用 颜色查找表 example LUT applyColorMap // 读入制作好的lut.png Mat color = imread("D:/images/lut.png&q ...
- C语言:将3*4矩阵中找出行最大,列最小的那个元素。-将低于平均值的人数作为函数返回值,将低于平均分的分数放入below数组中。
//将3*4矩阵中找出行最大,列最小的那个元素. #include <stdio.h> #define M 3 #define N 4 void fun(int (*a)[N]) { ,j ...
- Centos610安装Jdk1.8
1.下载JDK 下载: https://pan.baidu.com/s/15TYsE_wfSb48pS4SpUQKHA 提取码:fsx6 2.上传安装包 上传到linux 并拷贝到/opt/jdk目 ...
- Net Core解决ZipFile解压中文出现乱码
一.在main方法中添加 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 二.解压添加 //sourceArchiveFi ...
- 【代码审计】PHPCMS2008任意代码执行漏洞
很老的漏洞了,但很经典~ 在 phpcms2008/include/global.func.php eval 可以执行命令 在这里我们看一下是谁调用 跟进string2array函数 yp/web/ ...
- Spring Boot Shiro 使用教程
Apache Shiro 已经大名鼎鼎,搞 Java 的没有不知道的,这类似于 .Net 中的身份验证 form 认证.跟 .net core 中的认证授权策略基本是一样的.当然都不知道也没有关系,因 ...
- netty实现websocket客户端(附:测试服务端代码)
1,客户端启动类 package test3; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.Unpooled; import ...
- LeetCode简单题(四)
题目一: 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能同时参与多笔交易(你 ...