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. HDU5840(SummerTrainingDay08-B 树链剖分+分块)

    This world need more Zhu Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  2. Vue, element-ui Module build failed: Error: No PostCSS Config found

    使用vue框架写pc页面时,我们经常会用到element-ui这个框架. 当我们吧把需要的东西都装在好运行项目的时候,有时会出现这样的错误, Module build failed: Error: N ...

  3. 《JavaScript DOM 编程艺术》读书笔记

    <JS DOM 编程艺术>笔记 一. 三种节点 元素节点.文本节点.属性节点 二. 获取元素 1.document.getElementById 2.(element)document.g ...

  4. Angular 实现Bootstrap ScrollSpy控件

    Bootstap是基于JQuery开发,Angular中不支持Bootstrap相关事件逻辑.本文基于Typecript开发了一个Angular可用的ScrollSpy控件.Scrollspy控件主要 ...

  5. HTML初学小技巧

    01.让背景图不滚动IE浏览器支持一个 Body 属性 bgproperties,它可以让背景不滚动:〈Body Background="图片文件" bgproperties=&q ...

  6. codevs1735 方程的解数(meet in the middle)

    题意 题目链接 Sol 把前一半放在左边,后一半放在右边 meet in the middle一波 统计答案的时候开始想的是hash,然而MLE了两个点 实际上只要排序之后双指针扫一遍就行了 #inc ...

  7. 【读书笔记】iOS-报刊杂志-Newsstand应用编程

    一,使用Newsstand Kit API 苹果公司在iOS5之后提供了电子报刊杂志开发API-Newsstand Kit.Newsstand Kit 只有3个类:NKLibrary,NKIssue和 ...

  8. SpringMVC—Struts2拦截器学习网址整理

    引自:http://blog.csdn.net/wp1603710463/article/details/49982683 SpringMVC—Struts2拦截器学习网址整理 最近项目中遇到权限相关 ...

  9. 活字格Web应用平台学习笔记2-基础教程-开始

    今天先学活字格第一个教程,开始. 目标是能够用活字格创建一个简单的Web页面. 哈哈,简单,跟Excel一样,做单元格输入.合并.文字居中.加底色.加图片,然后发布. 然后就真的生成了一个Web页面! ...

  10. SQLServer 常见SQL函数

    SQL Server SQL函数 by:授客 QQ:1033553122 字符函数 日期函数 数学函数 系统函数