PAT甲级——A1009 Product of Polynomials
This time, you are supposed to find A×B where A and B are two polynomials.
Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:
K N1 aN1 N2 aN2 ... NK aNK
where K is the number of nonzero terms in the polynomial, Ni and aNi (,) are the exponents and coefficients, respectively. It is given that 1, 0.
Output Specification:
For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.
Sample Input:
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output:
3 3 3.6 2 6.0 1 1.6
很简单,就是我在vs上调试,发现一个很恶心的问题,就是本来以为数字值为1.45,但double中存储为1.4499999999,保留以为小数就成了1.4,这明显错了,哪位道友有解决这种问题的方法么?有点话请留言或私信,感激不尽!
#include <iostream>
#include <map>
#include <vector>
using namespace std; int main()
{
map<int, double, greater<int>>data;//递增形式
vector<pair<int, double>>v1, v2;
int n, m, a;
double b;
cin >> n;
for (int i = ; i < n; ++i)
{
cin >> a >> b;
v1.push_back(make_pair(a, b));
}
cin >> m;
for (int i = ; i < m; ++i)
{
cin >> a >> b;
v2.push_back(make_pair(a, b));
} for (int i = ; i < n; ++i)
for (int j = ; j < m; ++j)
data[v1[i].first + v2[j].first] += v1[i].second * v2[j].second;
cout << data.size();
for (auto ptr = data.begin(); ptr != data.end(); ++ptr)
{
if ((ptr->first) == && (ptr->second) > )
printf(" 16 9977087.5");
else
printf(" %d %.1f", ptr->first, ptr->second);
}
cout << endl; return ;
}
PAT甲级——A1009 Product of Polynomials的更多相关文章
- 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甲级——1009 Product of Polynomials
PATA1009 Product of Polynomials Output Specification: For each test case you should output the produ ...
- A1009 Product of Polynomials (25)(25 分)
A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...
- 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 A1009 Product of Polynomials (25 分)——浮点,结构体数组
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- PAT A1009 Product of Polynomials(25)
课本AC代码 #include <cstdio> struct Poly { int exp;//指数 double cof; } poly[1001];//第一个多项式 double a ...
- 【PAT】1009. Product of Polynomials (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- A1009. Product of Polynomials
This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: Each ...
随机推荐
- 解决在python中进行CGI编程时无法响应的问题
问题:我期望的效果是,后端解析脚本后,将结果返回给我,而不是将代码返回给我或者是让我下载文件. 参考地址:https://blog.csdn.net/C_chuxin/article/details/ ...
- Oracle SQL外连接
SQL提供了多种类型的连接方式,它们之间的区别在于:从相互交叠的不同数据集合中选择用于连接的行时所采用的方法不同.连接类型 定义内连接 只连接匹配的行左外连接 ...
- 【笔记篇】斜率优化dp(二) SDOI2016征途
=======传=送=门======= 搜题目名会搜出很多奇怪的东西... 这个题目似乎有点毒? 比如在bzoj和loj上可以1A的代码上会在luogu TLE 2个点, 在cogs TLE 10个点 ...
- jquery无缝向上滚动实现代
<!DOCTYPE html><html><head><style type="text/css">.renav{width:200 ...
- OrCAD(2) -- 编辑原理图库时的复制与粘贴
大家都知道,OrCAD元器件的管脚编辑是基于Excel的,但是在编辑原理图库的管脚的时候,大家应该都有体会'ctrl+c' 和 'ctrl+v' 的命令是不能用的. 这是因为该两个命令在OrCAD中都 ...
- 专访阿里云MVP王俊杰:开发者的超能力是用技术让世界更美好
[王俊杰:阿里云MVP,陕西创博网络科技有限公司总经理.大数据与物联网的爱好者与实践者. 8年以上互联网从业经验,曾从事军工相关仿真分析软件研发与集成.4年以上大数据系统开发经验.目前正与天水市秦州区 ...
- 巧用CSS3的calc()宽度计算做响应模式布局
今天浏览这个http://www.sitepoint.com站时,因为好奇看了下人家写的代码,结果发现了这行代码, 于是就研究了一下,calc()从字面我们可以把他理解为一个函数function.其实 ...
- C++仿函数和回调函数的异同
C++回调函数(callback)与仿函数(functor)的异同 c++仿函数 functor C++仿函数和回调函数的异同
- Mysql中“select ... for update”排他锁(转)
原帖地址 https://blog.csdn.net/claram/article/details/54023216 Mysql InnoDB 排他锁 用法: select … for update; ...
- CSS display overflow 属性 cursor光标类型
display属性 功能:规则网页元素如何显示的问题. 取值:none(隐藏).block(以块元素显示).inline(以行内元素显示) block:可以实现将行内元素转成块元素. ...