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 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
#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 分)——浮点,结构体数组的更多相关文章
- 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 ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- PAT A1009 Product of Polynomials(25)
课本AC代码 #include <cstdio> struct Poly { int exp;//指数 double cof; } poly[1001];//第一个多项式 double a ...
- 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 ...
- 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 ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT A1075 PAT Judge (25 分)——结构体初始化,排序
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
- 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 ...
随机推荐
- Android-远程Service
http://blog.csdn.net/guolin_blog/article/details/9797169 http://www.jianshu.com/p/eeb2bd59853f 将一个普通 ...
- element ui 的Notification通知如何加 a 标签和按钮,并弹多个
前言:工作中需要在页面右下角弹出很多个提醒框,提醒框上有一个可点击的a标签,并有一个按钮,同时还需要一次性关闭所有的弹出框.转载请注明出处:https://www.cnblogs.com/yuxiao ...
- 桥接模式(Bridge)
1.概念 桥接模式将抽象部分与它的实现部分分离,使它们都可以独立地变化,属于结构性模式的一种. 2.模式结构 Abstraction(抽象类):定义抽象接口,拥有一个Implementor类型的对象引 ...
- 【读书笔记】iOS-关闭键盘的2种方法
一种是通过使用键盘上的return键关闭键盘,一种是通过触摸背景关闭键盘. 参考资料:<iOS7开发快速入门>
- JavaSE——多线程
进程和线程: 进程是指运行中的应用程序,每一个进程都有自己独立的内存空间.一个应用程序可以启动多个进程. 线程是指进程中的一个执行流程,有时也称为执行情景. 线程和进程的主要区别在于:每个进程都需要操 ...
- [Android] TableLayout
public class TableLayout extends LinearLayout 查过文档,整理下要点: 一个 TableLayout 包含一些 TableRow 对象,每个对象代表一行.除 ...
- Java web 开发填坑记 2 -如何正确的创建一个Java Web 项目
转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/72566261 本文出自[赵彦军的博客] Java web 开发填坑记 1-如何正确 ...
- LeetCode 题解之 Positions of Large Groups
1.题目描述 2.问题分析 从头遍历字符串,使用一个局部迭代器和局部变量记录该字符个数.如果个数>= 3 ,则将此时的迭代器位置和局部迭代器的位置保存到局部vector中.再将这个局部vecto ...
- Python Socket 通信
参考: http://www.cnblogs.com/alex3714/articles/5830365.html Socket A network socket is an endpoint of ...
- Ionic 启动及应用图标
1.在项目的根目录下创建resources文件夹. 2.在文件夹中都放入icon.png(应用图标,最小192x192px,不带圆角),splash.png(启动屏幕,最小2208x2208px,中间 ...