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
#include <stdio.h>
#include <stdlib.h> struct poly{
int exp;
float a;
};
poly p1[];
double p2[] = { };
const double ep = 1e-;
int main(){
int k1, k2, exp;
double a;
scanf("%d", &k1);
for (int i = ; i < k1; i++){
scanf("%d %lf", &exp, &a);
p1[i].exp = exp;
p1[i].a = a;
}
getchar();
int count = ;
scanf("%d", &k2);
for (int i = ; i < k2; i++){
scanf("%d %lf", &exp, &a);
for (int j = ; j < k1; j++){
double tmp = p1[j].a*a;
if (p2[exp + p1[j].exp] == && tmp != ){
count++;
}
p2[exp + p1[j].exp] += tmp;
if (p2[exp + p1[j].exp] == )count--;
}
}
printf("%d", count);
for (int i = ; i >= ; i--){
if (p2[i] != 0.0){
printf(" %d %.1f", i, p2[i]);
}
}
system("pause");
}

注意点:一开始测试点0一直没通过,查了一下是相乘以后再加起来为0,然后以为是精度问题,发现怎么设置ep都不对,后来才知道原来是count计数错了,变为0的count会多加一次。当时在计算时就统计count是怕超时,结果发现多遍历一遍数count不会超时,反而不会错,应该是测试数据没有很大的。

PAT A1009 Product of Polynomials (25 分)——浮点,结构体数组的更多相关文章

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

  2. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

  3. PAT A1009 Product of Polynomials(25)

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

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

  6. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  7. PAT A1075 PAT Judge (25 分)——结构体初始化,排序

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  8. PAT 甲级 1012 The Best Rank (25 分)(结构体排序)

    题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...

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

随机推荐

  1. python协程的简单了解

    协程: 协程,又称微线程,纤程.英文名Coroutine. 可以在不同的函数间切换,而且切换的次数和时间都是由用户自己确定的. 协程的几种实现方式: (1)使用生成器yield实现. 如果不了解生成器 ...

  2. 解读 --- 基于微软企业商务应用平台 (Microsoft Dynamics 365) 之上的人工智能 (AI) 解决方案

    9月25日微软今年一年一度的Ignite 2017在佛罗里达州奥兰多市还是如期开幕了.为啥这么说?因为9月初五级飓风厄玛(Hurricane Irma) 在佛罗里达州登陆,在当地造成了挺大的麻烦.在这 ...

  3. Monkey Android app稳定性测试工具之Monkey使用教程

    Monkey Android app稳定性测试工具之Monkey使用教程 by:授客 QQ:1033553122 由于篇幅问题,仅提供百度网盘下载链接: Android app稳定性测试工具之Monk ...

  4. VMware 创建VMware9虚拟机及设置详细教程

    创建VMware9虚拟机及设置详细教程 by:授客 QQ:1033553122 1.点击Create a New Virtual Machine图标按钮,或者file->new virtual ...

  5. 安卓开发_浅谈ListView(ArrayAdapter数组适配器)

    列表视图(ListView)以垂直的形式列出需要显示的列表项. 实现过程:新建适配器->添加数据源到适配器->视图加载适配器 在安卓中,有两种方法可以在屏幕中添加列表视图 1.直接用Lis ...

  6. Android 如何执行java命令

    android的程序基于java开发,当我们接上调试器,执行adb shell,就可以执行linux命令,但是却并不能执行java命令. 那么在android的shell中是否就不能执行java程序了 ...

  7. 代码操作Word时,目录自动更新的两种方法

    最近的项目中有一个功能点为:根据分析数据库并生成报告.不过不是大数据.数据挖掘之类,报告的内容.组织方式都是事先固定下来的.实现的方式为,在普通word文档中插入书签制成模板,然后程序使用OpenXM ...

  8. Android Fragment的用法(二)

    如果你经常使用平板电脑,应该会发现很多的平板应用现在都采用的是双页模式(程序会在左侧的面板上显示一个包含子项的列表,在右侧的面板上显示内容),因为平板电脑的屏幕足够大,完全可以同时显示下两页的内容,但 ...

  9. MySQL自带的性能压力测试工具mysqlslap

    mysqlslap是从MySQL的5.1.4版开始就开始官方提供的压力测试工具. 通过模拟多个并发客户端并发访问MySQL来执行压力测试,同时提供了较详细的SQL执行数据性能报告,并且能很好的对比多个 ...

  10. Django之cookie&session

    cookie Cookie 是在 HTTP 协议下,服务器或脚本可以维护客户工作站上信息的一种方式.Cookie 是由 Web 服务器保存在用户浏览器(客户端)上的小文本文件,它可以包含有关用户的信息 ...