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. android 开发-AsyncTask异步任务的实现

     AsyncTask实现的原理,和适用的优缺点 AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作,并提供接口反馈当前异步执行的程度(可以通过 ...

  2. web 单例 多例

    单例多例需要搞明白两个问题:1. 什么是单例多例:2. 如何产生单例多例:3. 为什么要用单例多例4. 什么时候用单例,什么时候用多例:1. 什么是单例多例:所谓单例就是所有的请求都用一个对象来处理, ...

  3. php 转码函数 你还在用iconv吗?-- 解决sqlserver插入中文失败问题

    文章来源 :http://www.veryhuo.com/a/view/41348.html 这次给客户同步sqlserver数据,临时搭的 PHP Query Analyzer 插入某些中文一直有些 ...

  4. java如何调用服务端的WSDL接口

    如何使用http://192.168.0.170:8090/kaoshi?wsdl调用服务端暴露在外面可以使用的接口 1.首先创建调用ws的web项目,就一个普通的web项目就行: 2.通过eclip ...

  5. python类型之间的转换

    *int(x,base=10)x字符串或数字,base进制数,默认十进制 浮点转为整数 *float 整数转换为浮点型 *complex(1,2) 转换为复数 *str(10)将对象转换为字符串 *r ...

  6. 比例缩放 on() prop() 正则表达式

    $('#banner-section').css('height',$(window).width() / 1900 * 490 ); $(window).resize(function(){    ...

  7. Tomcat8

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

  8. SQLServer从其他表获取的数据更新该表的一部分

    在网上常见的是update  a  set  username  =  username  FROM b  on a.userid=b.userid,该更新语句是对a表中所有行进行更新.如果只更新一部 ...

  9. 关于docker容器内核参数修改问题

    以下内容截取自docker官方文档 地址:https://docs.docker.com/edge/engine/reference/commandline/run/#configure-namesp ...

  10. 弹出页面第一次加载可以生成table和方法的绑定,第二次点击进来不能生成table和方法的帮定

    问题原因: 弹出页面的写法是每次点击都会在原有页面基础之上新添加一个将其覆盖,原有页面不关闭.我用的生成table和点击事件的绑定是id选择器.页面中只绑定第一次的页面,第二次的页面作用不上. 解决: ...