两个多项式的乘积

两个数组,一个放多项式1,一个放结果

注意:arr2[j+exp]+=arr1[j]*coe; 因为有指数相加相同的情况下需要合并系数

 #include<cstdio>
int main(){
double arr1[]={0.0},arr2[]={0.0},coe;
int exp,count=,n,m;
scanf("%d", &n);
for(int i=;i<n;i++){
scanf("%d%lf",&exp,&coe);
arr1[exp]=coe;
}
scanf("%d", &m);
for(int i=;i<m;i++){
scanf("%d%lf", &exp,&coe);
for(int j=;j<=;j++)
arr2[j+exp]+=arr1[j]*coe;//加出来指数相同的系数要相加
}
for(int i=;i<=;i++){
if(arr2[i]!=0.0)
count++;
}
printf("%d",count);
for(int i=;i>=;i--){
if(arr2[i]!=0.0) printf(" %d %.1lf",i,arr2[i]);
}
return ;
}

A1009的更多相关文章

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

  2. PTA A1009&A1010

    第五天 A1009 Product of Polynomials (25 分) 题目内容 This time, you are supposed to find A×B where A and B a ...

  3. A1009. Product of Polynomials

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

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

  5. PAT A1009 Product of Polynomials(25)

    课本AC代码 #include <cstdio> struct Poly { int exp;//指数 double cof; } poly[1001];//第一个多项式 double a ...

  6. PAT甲级——A1009 Product of Polynomials

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

  7. PAT/简单模拟习题集(二)

    B1018. 锤子剪刀布 (20) Discription: 大家应该都会玩"锤子剪刀布"的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负 ...

  8. iot表和heap表排序规则不同

    SQL> select * from (select * from t1 order by id ) where rownum<20; ID A1 A2 A3 ---------- --- ...

  9. Oracle 排序规则

    <pre name="code" class="html">SQL> select * from t1 where id>=1 and ...

随机推荐

  1. 基于原生XMLHttpRequest封装

    用了一段时间的Ajax,感觉有很多的不足之处,于是就封装原生了 XMLHttpRequest . 废话不多说,直接上代码. var http = function () { 'use strict'; ...

  2. is_displayed()检查元素是否可见

    返回的结果是bool类型,以百度首页为案例,来验证"©2019 Baidu 使用百度前必读意见反馈京ICP证030173号 "是否可见,见实现的代码: from selenium ...

  3. http协议组成

    摘要 本文主要内容介绍什么是http协议 了解http协议之前我们先了解一下当我们输入一个url到页面渲染出来,这个过程发什么了什么呢~ 网络开启线程开始解析url DNS解析域名,查询IP 建立TC ...

  4. idea的掌握

    1:idea的界面了解(一般都会勾选这两项,编码比较方便) 2: 如何配置sdk(jdk,最后一个生成的是.class文件的位置) 3: 如何单个项目配置和全局配置 4:如何配置项目的jdk编译版本和 ...

  5. linux系统高级命令进阶

    输出重定向 >:覆盖文件内容 echo "123" > test:把原来的内容覆盖 echo "123" >> test:把原来的存在( ...

  6. linux/work

    0.切换用户 //默认root用户是无固定密码的,并且是被锁定的,如果想给root设置一个密码 sudo passwd root //输入密码 & 确认密码 //切换root用户 su roo ...

  7. python函数-内置函数

    官方文档[http://www.cnblogs.com/dingkailinux/p/7954484.html] 1.int()函数,表示整形,如 1,2,-1,-2. 2.float()函数,表示浮 ...

  8. 分享一个linux系统中循环遍历两个数组内容,并输出数组中的不同内容的shell脚本

    cat diffarray.sh #!/bin/bash arry_list1=(1 2 3 4 5 6 7 8 9) arry_list2=(3 5 8) declare -a diff_list ...

  9. Linux 系统多台主机之间做SSH免密码登陆

    SSH 免密登录 环境说明 CentOS 7.3 关键点 免密登录的关键点在于理解谁登录谁. A 生成的公钥给 B,也给 C.D,则 A 可以直接免密 SSH 登录 B.C.D A 生成密钥 在 A ...

  10. 分布式均匀算法--hash性一致算法--hash slot(转)

    目录 1.redis cluster介绍 2.最老土的hash算法和弊端(大量缓存重建) 3.一致性hash算法(自动缓存迁移)+虚拟节点(自动负载均衡) 不用遍历    -->   hash算 ...