PAT 1009 Product of Polynomials (25)
来源:互联网 发布:开淘宝店到底怎么样 编辑:程序博客网 时间:2024/06/08 18:50
题目:
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 Input2 1 2.4 0 3.22 2 1.5 1 0.5
Sample Output3 3 3.6 2 6.0 1 1.6
我的程序:
#include<iostream>//#include<cstdio>#include<iomanip>using namespace std;struct p{ int m; double a;};int main(){ double mi[2001]={0};// int n=2; int k1,k2; cin>>k1; struct p *p1=new struct p [k1]; for(int i=0;i<k1;i++) { int x; double y; cin>>x>>y; p1[i].m=x; p1[i].a=y; } cin>>k2; struct p* p2 = new struct p [k2]; for(int i=0;i<k2;i++) { int x; double y; cin>>x>>y; p2[i].m=x; p2[i].a = y; } int count=0; for(int i=0;i<k1;i++) { for(int j=0;j<k2;j++) { int l=p1[i].m+p2[j].m; double r=p1[i].a*p2[j].a; mi[l] += r; } } for(int i=0;i<2001;i++) { if(mi[i]!=0) count++; } cout<<count; for(int i=2000;i>=0;i--) { if(mi[i]!=0) cout<<" "<<i<<" "<<fixed<<setprecision(1)<<mi[i]; }// system("pause"); return 0;}
有什么错误还有什么可以优化的方法,非常欢迎大家指出!一起进步!
阅读全文
0 0
- PAT 1009 Product of Polynomials (25)
- PAT 1009 Product of Polynomials (25)
- pat 1009 Product of Polynomials
- PAT 1009 Product of Polynomials
- 浙大PAT (Advanced Level) Practise 1009 Product of Polynomials (25)
- PAT 1009 Product of Polynomials (25)多项式乘积
- PAT (Advanced Level) Practise 1009Product of Polynomials (25)
- PAT 1009(甲级) Product of Polynomials
- PAT-甲级-1009 Product of Polynomials
- pat甲级1009:Product of Polynomials
- pat甲级1009-Product of Polynomials
- 1009. Product of Polynomials (25)-PAT
- 【PAT】1009. Product of Polynomials (25)
- (PAT)1009. Product of Polynomials (25)
- PAT 1009. Product of Polynomials (25)
- PAT A 1009. Product of Polynomials (25)
- PAT 1009. Product of Polynomials (25)
- PAT 1009. Product of Polynomials (25)
- Linux下如何查看你的disk的信息
- 第十周 项目二
- 对于Vue-cli的路由跳转以及使用vue.js动态修改CSS样式
- 关于canvas无法通过drawImage加载的原因
- Flume_Channel
- PAT 1009 Product of Polynomials (25)
- 分布式锁与实现(一)——基于Redis实现
- Nginx的简单介绍和安装
- UILabel文字的调整
- React创建组件的三种方式及其区别
- UncaughtExceptionHandler线程异常终止处理
- linux中正则表达式、find、xargs、grep以及sed等命令的用法
- spring Security4 和 oauth2整合 注解+xml混合使用(替换用户名密码认证)
- 一文读懂Go的net/http标准库