PAT1009
来源:互联网 发布:mac加载字幕 编辑:程序博客网 时间:2024/06/06 21:41
http://www.patest.cn/contests/pat-a-practise/1009
思路:用数组的下标对应指数,数组储存的值对应系数。记录每个多项式的最高次以减少运算量。
#include <stdio.h>#define maxn 1005#define LOCALusing namespace std;int main(){#ifdef LOCAL freopen("PAT1009.txt","r",stdin);#endif float a[maxn]={0},b[maxn]={0},c[2*maxn]={0}; int Ka,Kb,Kc=0,exp,expa=0,expb=0; scanf("%d",&Ka); while(Ka--){ scanf("%d",&exp); if(exp>expa){ //expa保存代数式a的最高次数 expa=exp; } scanf("%f",&a[exp]); } scanf("%d",&Kb); while(Kb--){ scanf("%d",&exp); if(exp>expb){ expb=exp; //expb保存代数式b的最高次数 } scanf("%f",&b[exp]); } for(int i=0;i<=expa;++i){ for(int j=0;j<=expb;++j){ c[i+j]+=a[i]*b[j]; } } for(int i=0;i<=expa+expb;++i){ if(c[i]!=0.0){ ++Kc; } } printf("%d",Kc); for(int i=expa+expb;i>=0;--i){ if(c[i]!=0.0){ printf(" %d %.1f",i,c[i]); } } return 0;}
0 0
- PAT1009
- pat1009
- pat1009
- PAT1009
- PAT1009
- PAT1009总结
- PAT1009. Product of Polynomials
- PAT1009. 说反话
- PAT1009. 说反话
- PAT1009. Product of Polynomials
- pat1009 Product of Polynomials
- PAT1009说反话 (20)
- PAT1009:说反话
- PAT1009-说反话 (20)
- pat1009:说反话
- PAT1009 说反话 (20)
- PAT1009. 说反话 (20)
- PAT1009. 说反话 (20)
- 动态规划 背包问题
- 关于C++中的POD型别
- OPENCV中函数cvFilter2D的应用
- 线程追踪方法
- 遇见你是今生最大的惊喜。
- PAT1009
- GoEasy在web端推送及接收
- 华为路由器ACL简单配置
- 母函数习题
- main之前会执行什么代码
- 浅谈linux系统移植
- html+css+javascript 基础知识(二)
- Android Studio jni开发 串口通信
- 开通博客,以后每天发博文学习交流