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. 设计模式-组合模式(Composite)

    一.概念 将对象组合成树形结构以表示“部分-整体”的层次结构.组合模式使得用户对单个对象和组合对象的使用具有一致性. 二.模式动机 组合模式,通过设计一个抽像的组件类,使它既代表叶子对象,又代表组合对 ...

  2. Chromium源码--网络请求流程分析

    转载请注明出处:http://www.cnblogs.com/fangkm/p/3784660.html 本文探讨一下chromium中加载URL的流程,具体来说是从地址栏输入URL地址到通过URLR ...

  3. 百度自动推送js

    <!DOCTYPE html> <!-- saved from url=(0014)about:internet --> <html> <head> & ...

  4. css3 之 display 属性

    1.定义 语法:display:none | inline | block | list-item | inline-block | table | inline-table | table-capt ...

  5. [性能调优]在PeopleSoft中使用函数索引

    那些没有在PeopleSoft系统遇到性能问题的人,特别是基于Oracle数据库的PeopleSoft,可能不知道基于函数的索引. 根据定义,基于函数的索引是使用如下方法定义的: 基于表达式,例如算术 ...

  6. hihocoder [Offer收割]编程练习赛12 [1495] ---- 矩形分割

    原题链接 矩形分割 算法分析: 解决该题要用到"并查集"的思想. 这里有一篇不错的博客介绍并查集: 并查集(Union-Find)算法介绍 记 int total=N*M,这里会有 ...

  7. linux svn配置与使用

      svn错误码对照表: http://docs.sharpsvn.net/current/html/T_SharpSvn_SvnErrorCode.htm   https://www.cnblogs ...

  8. 【three.js练习程序】旋转、缩放场景

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. chrome中workspace配置达到同步修改本地文件的作用

    在前端开发中,我们经常需要在浏览器中进行调试,特别是一些样式的修改,如果你还是先在浏览器elements中调试好在复制到本地文件,那就真的out了. chrome浏览器的workspace功能完全可以 ...

  10. 如何使用 Swift 开发简单的条形码检测器?

    [编者按]本文作者为 Matthew Maher,主要手把手地介绍如何用 Swift 构建简单的条形码检测器.文章系 OneAPM 工程师编译整理. 超市收银员对货物进行扫码,机场内录入行李或检查乘客 ...