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 N​1​​ a​N​1​​​​ N​2​​ a​N​2​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (,) 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的更多相关文章

  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甲级——1009 Product of Polynomials

    PATA1009 Product of Polynomials Output Specification: For each test case you should output the produ ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. PAT A1009 Product of Polynomials(25)

    课本AC代码 #include <cstdio> struct Poly { int exp;//指数 double cof; } poly[1001];//第一个多项式 double a ...

  8. 【PAT】1009. Product of Polynomials (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...

  9. A1009. Product of Polynomials

    This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: Each ...

随机推荐

  1. neo4j常用cypher语句

    阅读更多 1.删除带有关系的节点   a.先删除关系 match (n:Node)-[r:关系名称]-() where (n...条件) delete r   b.删除节点 match (n:Node ...

  2. 关于__init__.py

    假设程序目录结构如下: ├── checkpoints/ ├── data/ │ ├── __init__.py │ ├── dataset.py │ └── get_data.sh ├── mode ...

  3. shell 命令 修改文件权限 chmod

    1. 所有者+.-权限 更改那个拥有者的权限 u  表示文件的所有者 g  表示文件所在的组 o  表示其他用户 a  所有,以上三者 增加 / 减少权限 + 表示增加权限 - 表示取消权限 更改具体 ...

  4. Java动态代理与CGLib

    Java帝国之动态代理 CGLib:从兄弟到父子-动态代理在民间是怎么玩的? 以上两篇文章引用自微信公众号: 码农翻身 Java动态代理 深度详解 以上文章引用博客园:陈树义

  5. 【JZOJ6287】扭动的树

    description analysis 区间\(DP\),首先按照键值排个序,这样保证树的中序遍历就为原序列 设\(f[0][i][j]\)表示\([i..j]\)区间作为\([unknown..i ...

  6. 1002CSP-S模拟测试赛后总结

    晚上 我死了.T1全场AC只有我爆零了?? 还非常中二地写了个代码注释: 水题不假,但你不知道题水你更水么?? 碰到简单题就掉以轻心??还告诉自己不要掉以轻心…… 这下是真的滑天下之大稽了吧. 读题不 ...

  7. 边双联通分量缩点+树的直径——cf1000E

    题意理解了就很好做 题意:给一张无向图,任意取两个点s,t,s->t的路径上必经边数量为k 求这样的s,t,使得k最大 #include<bits/stdc++.h> #define ...

  8. python定时任务模块APScheduler

    一.简单任务 定义一个函数,然后定义一个scheduler类型,添加一个job,然后执行,就可以了 5秒整倍数,就执行这个函数 # coding:utf-8 from apscheduler.sche ...

  9. Docker系列(五):Docker网络机制(上)

    Linux路由机制打通网络 路由机制是效率最好的 docker128上修改Docker0的网络地址,与docker130不冲突 vi /usr/lib/systemd/system/docker.se ...

  10. (一)通过JAVA连接SAP (sapjco3.jar在Windows和MacOS上的配置)

    (一)通过JAVA连接SAP调用接口 (sapjco3.jar在Windows和MacOS上的配置) 一.sapjoc3.jar获取 由于sap官网提供的链接需要合作公司提供账号密码,如果商用请索要正 ...