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. webpack 3 优化

    编译时间太长 项目为多页面应用时,编译的时候每个入口都会读取依赖的路径,所以入口越多,会导致编译越慢 公用库提取 除了公用的框架(如 Vue.React)以外,不同页面所需要的第三方库可能不一样,而且 ...

  2. asp.net弹出窗口并返回值

    a.html <form name="form1" method="post" action=""> <a href=&q ...

  3. Mavlink消息包解析

    Byte Index 字节索引 Content 内容 Value 值 Explanation 说明 0 包起始标志 v1.0: 0xFE (v0.9: 0x55) 指示新消息帧的开始.在v1.0版本中 ...

  4. Tomcat8

    一.Apache Tomcat 8介绍 Tomcat 8.0.0-RC3 (alpha) Released                                                ...

  5. Miner3D Developer 开发工具

    ——可视化的数据挖掘整合工具 在开发项目中,客户的要求多种多样.当开发者面临高挑战的工作时,完全可以选择Miner3D这样的软件,依赖其强大的数据可视化的特点,以及其他的明显的技术优势,提供给最终用户 ...

  6. TAS5508 output changing

    1.如果信号从3th通道输入,正常就是从PWM5,6输出,现在要想从PWM7,8输出,就按照以下红线部分选择DAP CH5和DAP CH6,然后写入相应寄存器产生的12 bytes的数组数据即可.

  7. [Unity3D] 如何识别屏幕边缘

    出现的问题 Unity3D中长度单位是米 使用Screen.resolutions获取的屏幕信息单位是像素 也就是说,即使获取了屏幕相关信息及参数,也无法把信息转换成可在editor中使用的信息.当时 ...

  8. 【MFC】0xC0000005: 读取位置 0x00000020 时发生访问冲突

    原因:使用GetDlgItem()函数时需要先判断指针然后才可以使用. 错误代码: //重新建一个线程,查询帧同步 DWORD WINAPI SCsync_Thread(LPVOID Lparam) ...

  9. cms-友情链接实现静态化

    service: package com.open1111.service.impl; import java.util.List; import javax.servlet.ServletConte ...

  10. 用rem实现h5页面的编写

    一 静态页面的布局 将这段代码加到script中 (function(doc, win) { var docEl = doc.documentElement, resizeEvt = 'orienta ...