A1009 Product of Polynomials (25)(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 (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10, 0 <= NK < ... < N2 < N1 <=1000.

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

思考

先考虑怎么存第一个样例

比起初试,还是机试爆零更可怕一点,所以确实是在大三下没有把握住机会啊,这学期有3门课,不应该那么烂的。

最高幂次数是2000,因为最大情况是1000*1000。

另外全局变量初始化不赋值,c语言默认处理为0啊,那么养成初始化赋值的习惯是极好的。

【c语言问题系列教程之一】变量声明和初始化 - CSDN博客 https://blog.csdn.net/mylinchi/article/details/52652595

C语言中全局变量初始化的重要性!!! - CSDN博客 https://blog.csdn.net/macrohasdefined/article/details/8814804

AC代码

#include<stdio.h>
struct Poly{
int exp;
double cof;
}poly[1001];//幂次数决定个数,正如数组下标是幂次数一样
double ans[2005]={0};//存放结果
int main(){
int n,m,number=0;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d %lf",&poly[i].exp ,&poly[i].cof );
}//读入第一个多项式
scanf("%d",&m);
for(int i=0;i<m;i++){
int exp;
double cof;
scanf("%d %lf",&exp,&cof);//读入第二个多项式的一项
for(int j=0;j<n;j++){
ans[exp+poly[j].exp]+=(cof*poly[j].cof);//这个写法从A1042起步
}
}
for(int i=0;i<=2000;i++){//这里漏掉一个最高幂次数2000,就有两个测试点过不去
if(ans[i] !=0.0) number++;
}
printf("%d", number);
for(int i=2000;i>=0;i--){
if(ans[i] !=0.0){
printf(" %d %.1f",i ,ans[i]);//输出控制要注意
}
}
return 0;
}

A1009 Product of Polynomials (25)(25 分)的更多相关文章

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

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

  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

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

  5. PAT甲级——A1009 Product of Polynomials

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

  6. PAT 1009 Product of Polynomials

    1009 Product of Polynomials (25 分)   This time, you are supposed to find A×B where A and B are two p ...

  7. PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名

    题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...

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

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

随机推荐

  1. Fiddler 抓包工具总结(转)

    Fiddler 抓包工具总结   阅读目录 1. Fiddler 抓包简介 1). 字段说明 2). Statistics 请求的性能数据分析 3). Inspectors 查看数据内容 4). Au ...

  2. 使用random函数实现randint函数的功能

    首先说明一下 random函数是random模块中的一个函数 首先要导入random模块 import random random函数的功能 #生成某一范围(0-1)内的随机小数print(rando ...

  3. Windows 10 取消桌面右键“图像属性”、“图像选项”

    Windows 10 取消桌面右键"图像属性"."图像选项" 桌面右键 说明:在windows 10中,桌面右键出现"图像属性"." ...

  4. 【转发活动】Hey, 是你吗? | 寻"粉"启示

    你知道吗 从 A computer on every desk and in every home 让每张办公桌上和每个家庭都有一台计算机 ▼ 到 Where do you want to go to ...

  5. k8s之configmap配置中心

    记录在石墨笔记中,懒得再粘贴了,大家直接移步下面地址 https://shimo.im/docs/ktNM72QPweEEkcWg/

  6. LeetCode Add Binary 两个二进制数相加

    class Solution { public: string addBinary(string a, string b) { if(a==""&&b==" ...

  7. 详情介绍win7:编辑文件夹时提示操作无法完成,因为其中的文件夹或文件已在另一个程序中打开的解决过程

    我们在使用电脑中,总会遇到下面这种情况: 那怎么解决呢,现在就开始教程: 在电脑的底下显示各种图标那一行点击右键,再选择“启动任务管理器” 接下来你就可以对你刚刚要操作的文件进行重命名.删除等操作啦! ...

  8. python内存泄露的诊断(转)

    本篇文章非原创,转载自:http://rstevens.iteye.com/blog/828565 . 对于一个用 python 实现的,长期运行的后台服务进程来说,如果内存持续增长,那么很可能是有了 ...

  9. pta 编程题13 File Transfer

    其它pta数据结构编程题请参见:pta 这道题考察的是union-find并查集. 开始把数组中每个元素初始化为-1,代表没有父节点.为了使树更加平衡,可以让每一个连通分量的树根的负值代表这个连通分量 ...

  10. IOS UIImageView的帧动画

    ● UIImageView可以让一系列的图片在特定的时间内按顺序显示 ● 相关属性解析: ● animationImages:要显示的图片(一个装着UIImage的NSArray) ● animati ...